Repository navigation
fix(docker): make the compose test path and the example run - #48
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make test(the compose test service,pytest -v --cov=.) did not run on master: on a clean clone theuv.lockmount failed, and with a lock in placepytestfailed at collection withImportError: No module named 'tests'. It runs and gives 0 failed here. The compose example service starts.uv.lockis gitignored in this repo (git ls-files uv.lockprints nothing), but the Dockerfile ranuv sync --extra dev --frozenandcompose.ymlbind-mounted./uv.lock. On a clean clone the build failed withUnable to find lockfileand, once the file was missing, Docker created a directory calleduv.lockon the host and the mount failed withnot a directory. I copied the guard-core pattern:uv sync --extra devwithout--frozenand nouv.lockmount.uv sync, so the project was never installed in the image and nothing put/apponsys.path. I addeduv pip install --python .venv/bin/python --no-deps -e /appafter the copy, which is what guard-core's Dockerfile does. That also fixes the collection error:tests.settingsis importable when pytest-django loads the settings, so I did not need apython -mworkaround.SecurityConfigdefaults toenable_redis=Trueandredis_url=redis://localhost:6379. Tests that build a config without aredis_urltherefore connect tolocalhost:6379inside the test container, where no Redis listens, and the middleware answers 503. Tests that hardcoded the URL now readREDIS_URLthe way the conftest does, and a session fixture intests/conftest.pypoints the engine default atREDIS_URLwhen it is set (it does nothing whenREDIS_URLis unset, so the CI service container on localhost still works). Files:tests/test_middleware.py,tests/conftest.py.gunicorn, which is not installed in the image. I addedgunicornto thedevextra (and to the deptry DEP002 ignore list next to the other dev tools). The command isgunicorn --chdir examples/simple example_project.wsgi:application ...withDJANGO_SETTINGS_MODULE=example_project.settings, the wayexamples/simple/compose.ymlruns it, because the example's settings importexample_project.urls.test_honeypot_form_detectionandtest_honeypot_json_detectionbuilt the request as aMagicMock. The engine checks the request against a runtime-checkable protocol (_BoundedBodyReader), which on 3.12 and later looks attributes up statically and does not see lazily created mock attributes. The tests now assignread_body_prefixas a real attribute.Verification, the compose test service run as the Makefile runs it, own compose project, Redis without a host port, master vs this branch:
No module named 'tests'), no test ran; branch 285 passed, 0 failed.uv.lock(a clean clone fails earlier, at the mount).compose.yml:healthy,GET /200,uid=10001.Not verified: Python versions other than 3.10 and 3.14, and the CI result (see the checks on this PR).