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

Comments

Projects
None yet
3 participants
@RockBomber
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

This comment has been minimized.

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

This comment has been minimized.

Contributor

RockBomber commented Jul 3, 2017

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

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Jul 3, 2017

Awesome, thanks!

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Aug 4, 2017

Fixed by #2559

@nicoddemus nicoddemus closed this Aug 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment