-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
get PYTEST_ADDOPTS before calling _initini #2824
get PYTEST_ADDOPTS before calling _initini #2824
Conversation
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.
looks like a good idea
please add tests
I added a test in 5bcdb52 - without the patch it fails - with the patch it passes. |
testing/test_config.py
Outdated
@@ -843,3 +843,10 @@ def test_with_existing_file_in_subdir(self, tmpdir): | |||
rootdir, inifile, inicfg = determine_setup(None, ['a/exist']) | |||
assert rootdir == tmpdir | |||
assert inifile is None | |||
|
|||
def test_addopts_before_initini(self, testdir, tmpdir, monkeypatch): | |||
monkeypatch.setenv('PYTEST_ADDOPTS', '-o cache_dir=/somewhere') |
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.
good thinking, for more pedantic separation i propose to replace the arbitrarily chosen /somewhere
by using testdir.join('somewhere')
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.
Done in 48c31f9. I had to use testdir.tmpdir.join(...)
though.
Shouldn't we target |
good call, lets re-target this to features |
I updated the PR to target the Just out of curiosity: what is roughly the timeline the changes on the |
the features branch is for minor versions primarily, we dont have a clear schedule as of now |
…on Windows We use shlex to parse command-line arguments and PYTEST_ADDOPTS, so passing a full path with '\' arguments produces incorrect results on Windows Anyway users are advised to use relative paths for portability
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 thanks.
Used a relative cache_dir
because a full path on Windows contains \
characters which are parsed incorrectly by shlex
.
While it works to pass
-o cache_dir=/somewhere
as command line arguments or set the option in thesetup.cfg
file I tried to achieve the same by setting the environment variablePYTEST_ADDOPTS="-o cache_dir=/somewhere"
. This doesn't work atm since the variable is only being considered after Config._initini has been called which e.g. decides on theoverride_ini
.To enable this use case this patch moves the call to
Config._initini
behind getting the environment variablePYTEST_ADDOPTS
. I didn't see any negative side effects of this change but I am new topytest
so might be missing something.I haven't added a test for this since I thought getting feedback in the patch first makes sense. If a test is desired please let me know and I am happy to do so.
I targeted
master
since the change is trivial. Please let me know if I should targetfeatures
instead.