Skip to content

Commit

Permalink
Merge pull request #2080 from nicoddemus/confcutdir-check
Browse files Browse the repository at this point in the history
Show an error if --confcutdir is not a valid directory
  • Loading branch information
nicoddemus authored Nov 23, 2016
2 parents a5b5090 + 629d8e9 commit 38f7562
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

*

*
* An error message is now displayed if ``--confcutdir`` is not a valid directory, avoiding
subtle bugs (`#2078`_).
Thanks `@nicoddemus`_ for the PR.


* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks
`@nedbat`_.
Expand All @@ -15,6 +18,7 @@
.. _@nedbat: https://github.com/nedbat

.. _#2038: https://github.com/pytest-dev/pytest/issues/2038
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078


3.0.4
Expand Down
6 changes: 5 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ def _warn_about_missing_assertion(self, mode):
"(are you using python -O?)\n")

def _preparse(self, args, addopts=True):
import pytest
self._initini(args)
if addopts:
args[:] = shlex.split(os.environ.get('PYTEST_ADDOPTS', '')) + args
Expand All @@ -1007,7 +1008,10 @@ def _preparse(self, args, addopts=True):
self.pluginmanager.load_setuptools_entrypoints(entrypoint_name)
self.pluginmanager.consider_env()
self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy())
if self.known_args_namespace.confcutdir is None and self.inifile:
confcutdir = self.known_args_namespace.confcutdir
if confcutdir and not os.path.isdir(confcutdir):
raise pytest.UsageError('--confcutdir must be a directory, given: {0}'.format(confcutdir))
if confcutdir is None and self.inifile:
confcutdir = py.path.local(self.inifile).dirname
self.known_args_namespace.confcutdir = confcutdir
try:
Expand Down
9 changes: 9 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ def pytest_addoption(parser):
assert len(l) == 2
assert l == ["456", "123"]

def test_confcutdir_check_isdir(self, testdir):
"""Give an error if --confcutdir is not a valid directory (#2078)"""
with pytest.raises(pytest.UsageError):
testdir.parseconfig('--confcutdir', testdir.tmpdir.join('file').ensure(file=1))
with pytest.raises(pytest.UsageError):
testdir.parseconfig('--confcutdir', testdir.tmpdir.join('inexistant'))
config = testdir.parseconfig('--confcutdir', testdir.tmpdir.join('dir').ensure(dir=1))
assert config.getoption('confcutdir') == str(testdir.tmpdir.join('dir'))


class TestConfigFromdictargs:
def test_basic_behavior(self):
Expand Down

0 comments on commit 38f7562

Please sign in to comment.