Skip to content

Commit

Permalink
Merge pull request #2824 from dirk-thomas/pytest_addopts_before_initini
Browse files Browse the repository at this point in the history
get PYTEST_ADDOPTS before calling _initini
  • Loading branch information
nicoddemus authored Oct 18, 2017
2 parents 71c76d9 + 10a3b91 commit 537fc3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,10 @@ def _warn_about_missing_assertion(self, mode):
"(are you using python -O?)\n")

def _preparse(self, args, addopts=True):
self._initini(args)
if addopts:
args[:] = shlex.split(os.environ.get('PYTEST_ADDOPTS', '')) + args
self._initini(args)
if addopts:
args[:] = self.getini("addopts") + args
self._checkversion()
self._consider_importhook(args)
Expand Down
1 change: 1 addition & 0 deletions changelog/2824.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow setting ``file_or_dir``, ``-c``, and ``-o`` in PYTEST_ADDOPTS.
8 changes: 8 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,11 @@ 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):
cache_dir = '.custom_cache'
monkeypatch.setenv('PYTEST_ADDOPTS', '-o cache_dir=%s' % cache_dir)
from _pytest.config import get_config
config = get_config()
config._preparse([], addopts=True)
assert config._override_ini == [['cache_dir=%s' % cache_dir]]

0 comments on commit 537fc3c

Please sign in to comment.