introduce --ignore option to ignore paths during collection

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-12-24 22:23:45 +01:00
parent cd96e52144
commit 6d46efa87a
4 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,9 @@
Changes between 1.1.2 and 1.1.1 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 - install 'py.test' and `py.which` with a ``-$VERSION`` suffix to
disambiguate between Python3, python2.X, Jython and PyPy installed versions. disambiguate between Python3, python2.X, Jython and PyPy installed versions.

View File

@ -394,8 +394,12 @@ class Directory(FSCollector):
return l return l
def _ignore(self, path): def _ignore(self, path):
ignore_paths = self.config.getconftest_pathlist("collect_ignore", path=path) ignore_paths = self.config.getconftest_pathlist("collect_ignore",
return ignore_paths and path in ignore_paths 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: # XXX more refined would be:
if ignore_paths: if ignore_paths:
for p in ignore_paths: for p in ignore_paths:

View File

@ -51,6 +51,8 @@ def pytest_addoption(parser):
group._addoption('-x', '--exitfirst', group._addoption('-x', '--exitfirst',
action="store_true", dest="exitfirst", default=False, action="store_true", dest="exitfirst", default=False,
help="exit instantly on first error or failed test."), 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', group._addoption('-k',
action="store", dest="keyword", default='', action="store", dest="keyword", default='',
help="only run test items matching the given " help="only run test items matching the given "

View File

@ -30,6 +30,15 @@ def test_plugin_already_exists(testdir):
assert config.option.plugins == ['default'] assert config.option.plugins == ['default']
config.pluginmanager.do_configure(config) 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: class TestDistOptions:
def setup_method(self, method): def setup_method(self, method):