Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using frame inspection to obtain feature file path is unreliable #401

Open
DrewDevereux opened this issue Feb 1, 2021 · 2 comments
Open

Comments

@DrewDevereux
Copy link

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.

@DrewDevereux
Copy link
Author

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.

@DrewDevereux
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant