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

Providing custom cache directory name through pytest argument #2543

Closed
RockBomber opened this issue Jul 3, 2017 · 4 comments
Closed

Providing custom cache directory name through pytest argument #2543

RockBomber opened this issue Jul 3, 2017 · 4 comments
Labels
status: help wanted developers would like help from experts on this topic type: enhancement new feature or API change, should be merged into features branch

Comments

@RockBomber
Copy link
Contributor

RockBomber commented Jul 3, 2017

Hello, All!

It is a feature request for providing custom cache directory name through pytest argument

I implemented this feature like this:

diff --git a/_pytest/cacheprovider.py b/_pytest/cacheprovider.py
index 7fc08ff..2ac4467 100755
--- a/_pytest/cacheprovider.py
+++ b/_pytest/cacheprovider.py
@@ -14,7 +14,8 @@ from os.path import sep as _sep, altsep as _altsep
 class Cache(object):
     def __init__(self, config):
         self.config = config
-        self._cachedir = config.rootdir.join(".cache")
+        dirname = config.getoption("cachedir")
+        self._cachedir = config.rootdir.join(dirname)
         self.trace = config.trace.root.get("cache")
         if config.getvalue("cacheclear"):
             self.trace("clearing cachedir")
@@ -171,6 +172,10 @@ def pytest_addoption(parser):
     group.addoption(
         '--cache-clear', action='store_true', dest="cacheclear",
         help="remove all cache contents at start of test run.")
+    group.addoption(
+        '--cache-dir', dest="cachedir", default='.cache',
+        help="directory name for cache content. "
+             "Default: %(default)s")
 
 
 def pytest_cmdline_main(config):

Can this feature be included in the next release?

@nicoddemus nicoddemus added the type: enhancement new feature or API change, should be merged into features branch label Jul 3, 2017
@RonnyPfannschmidt RonnyPfannschmidt added the status: help wanted developers would like help from experts on this topic label Jul 3, 2017
@nicoddemus
Copy link
Member

nicoddemus commented Jul 3, 2017

Hi @RockBomber thanks for writing.

I think this would be better implemented as an ini option, because it seems to me it should be a configuration reused all the time. It would still be possible to change that in the command line using -o command line flag.

Can this feature be included in the next release?

Would you like to open a PR with that? It would have to go to the features branch though, given that is a new feature, and would be available in pytest-3.2.0.

@RockBomber
Copy link
Contributor Author

Thank you for answer!
I will try to prepare PR on the weekends

@nicoddemus
Copy link
Member

Awesome, thanks!

@nicoddemus
Copy link
Member

Fixed by #2559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants