-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 through ini option #2558
Conversation
Awesome, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following through with absolute paths. 👍
I would like to add support for environment variables as well, but I will do it myself some time later.
Would you like to add environment variable like PYTEST_CACHEDIR? |
I hadn't thought about this specifically, but this might be a good idea. 😁
I meant to be able to expand variables in the config option (#1089): [pytest]
cache_dir=$XDG_CONFIG_DIR This would also mean that we can announce that we plan to change the default from Are you interested to tackle this as well? |
I can implement it like:
In my opinion, it's look better than |
I see, but the main point that I would like to have is environment variable expansion support in the Note that we can have both: Not sure which would take precedence... my initial gut feeling would be that # args is sys.argv
args[:] = shlex.split(os.environ.get('PYTEST_ADDOPTS', '')) + args
args[:] = self.getini("addopts") + args
|
In this case it may implemented like:
|
We can let let @staticmethod
def cache_dir_from_config(config):
cache_dir = config.getini("cache_dir")
cache_dir = os.path.expanduser(cache_dir)
cache_dir = os.path.expandvars(cache_dir)
if os.path.isabs(cache_dir):
return py.path.local(cache_dir)
else:
return config.rootdir.join(cache_dir) |
Looks more clear :) |
That would be great, thanks! 😁 |
(Just noticed there is a "First time contributor" small badge on the PR header, didn't know about this GH feature. Nice! 👍) |
testing/test_cache.py
Outdated
assert testdir.tmpdir.join(rel_cache_dir).isdir() | ||
|
||
def test_custom_abs_cache_dir(self, testdir): | ||
abs_cache_dir = os.path.abspath(testdir.tmpdir.join('custom_cache_dir').strpath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use a non-sibling of our tmpdir
, please use the tmpdir_factory
fixture to create a new temporary directory instead:
def test_custom_abs_cache_dir(self, testdir, tmpdir_factory):
abs_cache_dir = str(tmpdir_factory.mktemp('custom_cache_dir'))
Better to use a non-sibling directory to avoid this feature breaking in the future by accident.
Oh just remembered that this also needs a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just needs a changelog file and improve the test for absolute path a bit. 👍
Something goes wrong. I will do new PR. |
Providing custom cache directory name through ini option (issue #2543)