diff --git a/CHANGELOG b/CHANGELOG index 8fb8fb2ba..faa2b40fa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 1.1.2 and 1.1.1 ===================================== +- new option: --ignore will prevent specified path from collection. + Can be specified multiple times. + - install 'py.test' and `py.which` with a ``-$VERSION`` suffix to disambiguate between Python3, python2.X, Jython and PyPy installed versions. diff --git a/py/impl/test/collect.py b/py/impl/test/collect.py index 7f2940a10..02a0ec2a4 100644 --- a/py/impl/test/collect.py +++ b/py/impl/test/collect.py @@ -394,8 +394,12 @@ class Directory(FSCollector): return l def _ignore(self, path): - ignore_paths = self.config.getconftest_pathlist("collect_ignore", path=path) - return ignore_paths and path in ignore_paths + ignore_paths = self.config.getconftest_pathlist("collect_ignore", + path=path) or [] + excludeopt = self.config.getvalue("ignore") + if excludeopt: + ignore_paths.extend([py.path.local(x) for x in excludeopt]) + return path in ignore_paths # XXX more refined would be: if ignore_paths: for p in ignore_paths: diff --git a/py/plugin/pytest_default.py b/py/plugin/pytest_default.py index 96ad78321..1f71398d8 100644 --- a/py/plugin/pytest_default.py +++ b/py/plugin/pytest_default.py @@ -51,6 +51,8 @@ def pytest_addoption(parser): group._addoption('-x', '--exitfirst', action="store_true", dest="exitfirst", default=False, help="exit instantly on first error or failed test."), + group.addoption("--ignore", action="append", metavar="path", + help="ignore path during collection (multi-allowed).") group._addoption('-k', action="store", dest="keyword", default='', help="only run test items matching the given " diff --git a/testing/plugin/test_pytest_default.py b/testing/plugin/test_pytest_default.py index f6f2824c0..c10b6509b 100644 --- a/testing/plugin/test_pytest_default.py +++ b/testing/plugin/test_pytest_default.py @@ -30,6 +30,15 @@ def test_plugin_already_exists(testdir): assert config.option.plugins == ['default'] config.pluginmanager.do_configure(config) +def test_exclude(testdir): + hellodir = testdir.mkdir("hello") + hellodir.join("test_hello.py").write("x y syntaxerror") + hello2dir = testdir.mkdir("hello2") + hello2dir.join("test_hello2.py").write("x y syntaxerror") + testdir.makepyfile(test_ok="def test_pass(): pass") + result = testdir.runpytest("--ignore=hello", "--ignore=hello2") + assert result.ret == 0 + assert result.stdout.fnmatch_lines(["*1 passed*"]) class TestDistOptions: def setup_method(self, method):