diff --git a/AUTHORS b/AUTHORS index 35e07dcb412..737c07b1bab 100644 --- a/AUTHORS +++ b/AUTHORS @@ -50,6 +50,7 @@ Charles Cloud Charnjit SiNGH (CCSJ) Chris Lamb Christian Boelsen +Christian Fetzer Christian Theunert Christian Tismer Christopher Gilling diff --git a/changelog/3711.feature.rst b/changelog/3711.feature.rst new file mode 100644 index 00000000000..06a7f5355c8 --- /dev/null +++ b/changelog/3711.feature.rst @@ -0,0 +1 @@ +Add support for Unix shell-style wildcards to the ``--ignore`` parameter. diff --git a/doc/en/example/pythoncollection.rst b/doc/en/example/pythoncollection.rst index 8dcaa97d715..5bfd56955d7 100644 --- a/doc/en/example/pythoncollection.rst +++ b/doc/en/example/pythoncollection.rst @@ -41,6 +41,8 @@ you will see that ``pytest`` only collects test-modules, which do not match the ========================= 5 passed in 0.02 seconds ========================= +The ``--ignore`` option supports Unix shell-style wildcards. + Deselect tests during test collection ------------------------------------- diff --git a/src/_pytest/main.py b/src/_pytest/main.py index d0d826bb653..7c4cb294362 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -293,7 +293,9 @@ def pytest_ignore_collect(path, config): if excludeopt: ignore_paths.extend([py.path.local(x) for x in excludeopt]) - if py.path.local(path) in ignore_paths: + if any( + py.path.local(path).fnmatch(str(ignore_path)) for ignore_path in ignore_paths + ): return True allow_in_venv = config.getoption("collect_in_virtualenv") diff --git a/testing/test_session.py b/testing/test_session.py index d64a1a51978..78872a0f4e6 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -253,6 +253,21 @@ def test_exclude(testdir): result.stdout.fnmatch_lines(["*1 passed*"]) +def test_exclude_glob(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") + hello3dir = testdir.mkdir("hallo3") + hello3dir.join("test_hello3.py").write("x y syntaxerror") + subdir = testdir.mkdir("sub") + subdir.join("test_hello4.py").write("x y syntaxerror") + testdir.makepyfile(test_ok="def test_pass(): pass") + result = testdir.runpytest("--ignore=*h[ea]llo*") + assert result.ret == 0 + result.stdout.fnmatch_lines(["*1 passed*"]) + + def test_deselect(testdir): testdir.makepyfile( test_a="""