You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pytest-bdd uses frame inspection to obtain the path to its feature file. This in unreliable because
Pytest performs assert rewriting, and caches the rewritten modules. If I run pytest-bdd on my local system, where my tests are in "/projects/my-project/tests", then the cached rewritten modules will end up containing this path in their metadata.
If I then spin up a docker container, with my project mounted as "/app/my-project", then when I run my tests, pytest will load the cached rewritten modules, and the metadata will be wrong. This usually doesn't matter, but it matters to pytest-bdd, because pytest-bdd will get the wrong path, and go looking for its feature file in "/projects/my-project/tests/....", and crash with a FileNotFoundError.
The text was updated successfully, but these errors were encountered:
Workaround for the docker case is to have **/__pycache__ in your .dockerignore. But this doesn't fix the general issue of running locally or across a mount.
I am continuing to run into this issue when deploying the same test suite to different docker containers.
The above workaround is fine if you copy the test suite into your image at build stage. It doesn't help if you mount the test suite at container runtime.
For runtime, a workaround is always to run your tests with PYTHONDONTWRITEBYTECODE environment variable set to 1, or using -B option to python i.e. python -B -m pytest.
Pytest-bdd uses frame inspection to obtain the path to its feature file. This in unreliable because
Pytest performs assert rewriting, and caches the rewritten modules. If I run pytest-bdd on my local system, where my tests are in "/projects/my-project/tests", then the cached rewritten modules will end up containing this path in their metadata.
If I then spin up a docker container, with my project mounted as "/app/my-project", then when I run my tests, pytest will load the cached rewritten modules, and the metadata will be wrong. This usually doesn't matter, but it matters to pytest-bdd, because pytest-bdd will get the wrong path, and go looking for its feature file in "/projects/my-project/tests/....", and crash with a FileNotFoundError.
The text was updated successfully, but these errors were encountered: