Skip to content
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

Show an error if --confcutdir is not a valid directory #2080

Merged
merged 1 commit into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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