question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable the creation of the __pycache__ directory... From pytest.ini / pyproject.toml

See original GitHub issue

Problem Statement

In order to keep project directory structures clean and non-distracting, I’d like to:

  1. Prevent the creation of __pycache__ directories when running tests
  2. 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

  1. Set an environment variable during pytest invokation, eg, PYTHONDONTWRITEBYTECODE=1 pytest (see: #200)
  2. Create a post-test cleanup script to delete the cache
  3. 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 .gitignore file and creates cache directories at a local level.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
maxsucommented, Feb 12, 2022

@The-Compiler I think your argument is analagous to this:

Hi, I have a dog named Pytest, but it makes a mess. Can I train it to make less mess?

Look, I have five dogs, and they all make messes. So there’s no use training Pytest. Let it be a dog!

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!

1reaction
RonnyPfannschmidtcommented, Jan 19, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found