Disable the creation of the __pycache__ directory... From pytest.ini / pyproject.toml
See original GitHub issueProblem Statement
In order to keep project directory structures clean and non-distracting, I’d like to:
- Prevent the creation of
__pycache__directories when running tests - Control this behavior from existing config files (pytest.ini or pyproject.toml)
Use 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 a test-runner.sh.
Workarounds
- Set an environment variable during pytest invokation, eg,
PYTHONDONTWRITEBYTECODE=1 pytest(see: #200) - Create a post-test cleanup script to delete the cache
- Ignore the cache directories via
.gitignore
Caveats:
- Solutions 1 and 2 require the user to manually configure pytest behavior at invocation or pushes pytest behavior to an extra file (eg.
test-runner.sh). - Solution 3 cleans up the project at the git repository level but requires a
.gitignorefile and creates cache directories at a local level.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Preventing pytest from creating .cache directories in Pycharm
There are two basic options: disable the caching altogether (the caching is done with the cacheprovider plugin): pytest -p no:cacheprovider.
Read more >History - setuptools 65.6.3.post20221216 documentation
To disable this behaviour, use namespaces = False when explicitly setting the [tool.setuptools.packages.find] section in pyproject.toml . This change is ...
Read more >Configuring Flake8 — flake8 6.0.0 documentation
In our case, we keep our Flake8 configuration in tox.ini . ... our git directory .git, # There's no value in checking cache...
Read more >My How and Why: pyproject.toml & the 'src' Project Structure
My How and Why: pyproject.toml & the 'src' Project Structure ... this post near the top of the results list for a variety...
Read more >Flit Documentation
3.1 The pyproject.toml config file. This file lives next to the module or package. Note: Older version of Flit (up to 0.11) used...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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!
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