Skip to content

Commit ee24549

Browse files
committed
tests: fix lint, format tests; update devcontainer Makefile and test fixtures
1 parent 0dbbd50 commit ee24549

File tree

9 files changed

+480
-63
lines changed

9 files changed

+480
-63
lines changed

.coverage.onboard.7111.XFXYSZwx

-52 KB
Binary file not shown.

.devcontainer/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ test: uv.lock
3333
echo "behave not installed in uv environment, skipping BDD tests"; \
3434
fi
3535
@echo "Running ALL tests (excluding disabled tests)..."
36-
uv run --all-packages pytest tests/ --ignore=tests/support --cov=app --cov-report=term-missing --cov-report=html:.htmlcov -v
36+
# Run pytest but explicitly exclude integration tests during the regular test run
37+
uv run --all-packages pytest tests/ --ignore=tests/support --ignore=tests/integration \
38+
--cov=app --cov-report=term-missing --cov-report=html:.htmlcov -v
39+
40+
# Run full test suite including integration tests. This target depends on the
41+
# regular 'test' target so unit/BDD tests run first, then integration tests run
42+
# afterwards.
43+
test-integration: test
44+
@echo "Running integration tests..."
45+
uv run --all-packages pytest tests/integration --cov=app --cov-report=term-missing -v
3746

3847
# Run linting
3948
# E203: whitespace before ':' (conflicts with black formatting)

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
},
2222
"initializeCommand": "make initialize",
23-
"postCreateCommand": "chown -R ${USER}:${USER} ${PROJECT_PATH} && uv sync --dev && ./.devcontainer/setup-dotfiles.sh",
23+
"postCreateCommand": "sudo chown -R ${USER}:${USER} ${PROJECT_PATH} && uv sync --dev && ./.devcontainer/setup-dotfiles.sh",
2424
"runArgs": [
2525
"--name","${localWorkspaceFolderBasename}_devcontainer",
2626
"--hostname","${localWorkspaceFolderBasename}",

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ if [ "$(id -u)" = "0" ]; then
9393

9494
echo "Running as user ${USER}: $@"
9595
exec gosu ${USER} "$@"
96+
else
97+
# If not running as root, attempt to chown docker.sock using sudo if available
98+
if command -v sudo >/dev/null 2>&1; then
99+
sudo chown ${USER}:${USER} /var/run/docker.sock >/dev/null 2>&1 || true
100+
sudo chown -R ${USER}:${USER} ${HOME}
101+
fi
96102
fi
97103

98104
echo "Running: $@"
@@ -235,7 +241,8 @@ RUN --mount=type=cache,target=/var/cache/apt \
235241
RUN --mount=type=cache,target=/tmp/.cache/uv \
236242
--mount=type=cache,target=/root/.cache/pip \
237243
--mount=type=cache,target=/root/.cache/uv \
238-
uv sync --dev
244+
uv sync --dev && \
245+
chown -R $USER:$USER /usr/local/lib/python3.12/site-packages/
239246

240247
# Copy application code after dependency installation (keep package layout)
241248
COPY --chown=${USER}:${USER} app ${PROJECT_PATH}/

app/modules/testsupport.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44

55
def is_test_environment() -> bool:
6-
"""Centralized detection for test environments.
6+
"""Centralized detection for test environments.
77
8-
This function consolidates the heuristic used across the app for
9-
skipping scheduler startup and other test-only behavior.
10-
"""
11-
return (
12-
os.environ.get("ONBOARD_DISABLE_SCHEDULER", "False").lower() == "true"
13-
or "pytest" in sys.modules
14-
or "PYTEST_CURRENT_TEST" in os.environ
15-
or any("test" in arg for arg in sys.argv)
16-
or "behave" in sys.modules
17-
)
8+
This function consolidates the heuristic used across the app for
9+
skipping scheduler startup and other test-only behavior.
10+
"""
11+
return (
12+
os.environ.get("ONBOARD_DISABLE_SCHEDULER", "False").lower() == "true"
13+
or "pytest" in sys.modules
14+
or "PYTEST_CURRENT_TEST" in os.environ
15+
or any("test" in arg for arg in sys.argv)
16+
or "behave" in sys.modules
17+
)

tests/app/test_app_main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def register(self, name, bundle):
5252

5353
fake_flask_assets.Bundle = FakeBundle
5454
fake_flask_assets.Environment = FakeEnvironment
55-
sys.modules["flask_assets"] = fake_flask_assets
55+
monkeypatch.setitem(sys.modules, "flask_assets", fake_flask_assets)
5656

5757
# Execute the module as __main__ to run top-level code; it will import our fake
5858
try:
@@ -112,7 +112,7 @@ def register(self, name, bundle):
112112

113113
fake_flask_assets.Bundle = FakeBundle
114114
fake_flask_assets.Environment = FakeEnvironment
115-
sys.modules["flask_assets"] = fake_flask_assets
115+
monkeypatch.setitem(sys.modules, "flask_assets", fake_flask_assets)
116116

117117
try:
118118
sys.modules.pop("app.main", None)
@@ -148,8 +148,8 @@ def fake_serve(*a, **kw):
148148
return "SENTINEL"
149149

150150
fake_asyncio.serve = fake_serve
151-
sys.modules["hypercorn"] = fake_hypercorn_mod
152-
sys.modules["hypercorn.asyncio"] = fake_asyncio
151+
monkeypatch.setitem(sys.modules, "hypercorn", fake_hypercorn_mod)
152+
monkeypatch.setitem(sys.modules, "hypercorn.asyncio", fake_asyncio)
153153

154154
# Provide a fake Config class expected by the module
155155
fake_config_mod = types.ModuleType("hypercorn.config")
@@ -158,7 +158,7 @@ class FakeConfig:
158158
pass
159159

160160
fake_config_mod.Config = FakeConfig
161-
sys.modules["hypercorn.config"] = fake_config_mod
161+
monkeypatch.setitem(sys.modules, "hypercorn.config", fake_config_mod)
162162

163163
# Fake event loop with add_signal_handler and run_until_complete
164164
class FakeLoop:
@@ -200,7 +200,7 @@ def register(self, name, bundle):
200200

201201
fake_flask_assets.Bundle = FakeBundle
202202
fake_flask_assets.Environment = FakeEnvironment
203-
sys.modules["flask_assets"] = fake_flask_assets
203+
monkeypatch.setitem(sys.modules, "flask_assets", fake_flask_assets)
204204

205205
try:
206206
sys.modules.pop("app.main", None)

0 commit comments

Comments
 (0)