Pytest: .pytest_cache is showing up in projects git repos

Created on 6 Mar 2018  路  23Comments  路  Source: pytest-dev/pytest

i just noted that this started to happen, as far as i can tell the .cache rename was a breaking change for users

cache enhancement

Most helpful comment

its not clear to me either, but i started to note that people are affected by our change in a negative unintended way

All 23 comments

Not sure how this would be actionable for pytest?

its not clear to me either, but i started to note that people are affected by our change in a negative unintended way

People probably made the same mistake when we introduced pytest-cache into the core and hence .cache started to be created every time pytest executed.

I see that .pytest_cache already made into GitHub's default .gitignore file in https://github.com/github/gitignore/commit/f651f0d3eef062a8592e017a194e703d93f3e5c9, which is good.

@nicoddemus that doesnt help people updating their projects however

Indeed it does not, just thought I would mention that.

One thing that might help is to add a .pytest_cache/README file which explains what is the purpose of the directory and that it should not be added to version control. Of course few people will actually read that file, but other than that I'm out of ideas on how to improve the situation.

TBH I don't consider this critical, certainly a nuisance but not critical.

To comment on this, is there a way to configure this to be outside e.g in /tmp dir?
It's very annoying for two reasons:

  • we have few dozen projects we need to update the ignore files for
  • secondly, most annoying the full-text search in an IDE now also returns results from that directory which in some cases makes this search act very poorly because we get tons of hits from that cache files.

Hi @marcinkuzminski, you can use the cache_dir configuration option.

Should we close this in favor of https://github.com/pytest-dev/pytest/issues/3519? I don't think is there anything else that can be done about this issue. #3519 would be a nice improvement though.

Thanks for the pointer, however what confused me is that in docs it mentions that default is .cache so was it now renamed to .pytest_cache or is it something else?

Yeah that is a bug in the docs, it is supposed to be .pytest_cache. Fixed. 馃憤

We'll adjust our configuration based on the mentioned cache_dir setting. Thanks for the help and clarification.

@nicoddemus i beleive we should add a scheme that uses $(xdg-cachedir/pytest/folder-(hash of worktree) and a sheme that adds it in basetemp/cache-oneshot

This has been brought in the past in #1089, but the idea was shot down IIRC (don't have time to read the whole thread again now).

@nicoddemus actually it wasnt - it was back the same idea, i just accidentially reiterated it -

we should extend a bit on it and bacialyl have backend selection, and backend fallbacks (so nonwritable cwd will push the cache to the tmpdir for example)

@nicoddemus another devious idea - if we add a .gitignore with the content * then the folder is protected as well and people dont need to track manually

@nicoddemus another devious idea - if we add a .gitignore with the content * then the folder is protected as well and people dont need to track manually

Heh that's clever. Not sure if there would be any downsides to it, I can't think of any.

TBH I think this issue will be less and less important as time goes by, specially if we decide to implement #1089 and change the default to be outside the work tree.

We use Mercurial for example, so adding .gitignore would not really work in our case

sorry I haven't read the implementation of pytest_cache... but since I usually use tox should that cache end up on my .tox/env/ttmp that (I think) would be current dir

We use Mercurial for example, so adding .gitignore would not really work in our case

Good point, we should also add Mercurial and other systems (Bazaar, ?)

Does anybody see any drawback with having a .gitignore (and etc) with mask * in there? Seems like the perfect solution, solves the problem and trivial to implement.

git is the de facto winner of the scm wars due to the network effects - so lets add it, and be open for users of other systems to add support for their scm's

Hmm I agree. When I suggested to support other systems, I was under the impression that the most popular ones work similarly to .gitignore, as I have seen .hgignore multiple times. But reading the documentation I found you can only have a single .hgignore next to .hg, so this greatly complicates things. Same with Bazaar.

It is very hard to solve this issue for every SCM (except changing the location of .pytest_cache as depicted in #1089), so better to fix this with a simple solution for Git users rather than not solve this for everyone and linger this forever.

We can always change the solution later if we find a better way, after all.

Was this page helpful?
0 / 5 - 0 ratings