-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Disable the creation of the __pycache__ directory... From pytest.ini / pyproject.toml #9529
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
Comments
FWIW I'm -1 on this. Anything importing your module will lead to Python writing |
a possible consideration could be on whether pytest should support putting pyc files into the pytest cache folder based on a argument but thats not what this is about im also -1 on a pytest local option for this based on missed errors/issue in the past when running without bytecode |
@The-Compiler, unless I'm mistaken test-time creation of @RonnyPfannschmidt if testing without writing bytecode can lead to missed errors, that's a serious pain. That's unexpected to me, since the interpreter creates bytecode even if it doesn't cache to disk. On the other hand, if complex test scenarios would force the interpreter to create and re-create the bytecode during testing, this could make a horrifying kind of sense. A couple questions:
If workaround 2 is safe, then perhaps a solution is a pytest plugin that does post-test cleanup. |
Do you never import your code (nor use any tools which do so, other than pytest) while developing it? Even just having a script importing from an |
@The-Compiler I think your argument is analagous to this:
But I really do just testing in most sessions, and if I deal with one mess at a time, my environment stays clean. I would like to implement the feature and get it into the standard build or standard plugins. I would really appreciate suggestions that'll help the PR go through, thanks! |
This rhetoric doesn't seem to be very constructive. I tried to understand your use-case for this, if this is the answer I get, I'm out. |
@The-Compiler if I misunderstood and misrepresented your point, then I apologize. Most of the time I run only pytest, and want the option to run pytest without adding extra files to my source. I'm willing to deal with other tools on their own terms; this is part of an effort to deal with sources of cache files one tool at a time. I think that's reasonable. |
@nicoddemus @The-Compiler, I remain convinced that an option to suppress |
I think @The-Compiler's point is that any import you do in your test modules will result in |
I had a bit of an interesting SNAFU today where pyc's would be caching a host file path that would then be incorrect when running tests inside docker (python-dotenv blew up, I'm guessing because it does... interesting... tricks to find its own location - possibly something I should report there?). |
Problem Statement
In order to keep project directory structures clean and non-distracting, I'd like to:
__pycache__
directories when running testsUse Case
Simple projects that don't benefit from bytecode caching would benefit from a cleaner directory structure. A solution would consolidate pytest configuration and reduce the need for extra files, eg,
.gitignore
or atest-runner.sh
.Workarounds
PYTHONDONTWRITEBYTECODE=1 pytest
(see: disable the creation of the __pycache__ directory #200).gitignore
Caveats:
test-runner.sh
)..gitignore
file and creates cache directories at a local level.The text was updated successfully, but these errors were encountered: