Skip to content

Commit

Permalink
Add ability to use globs when using --ignore
Browse files Browse the repository at this point in the history
This changes the `--ignore` option to allow Unix-style wildcards so
that `--ignore=integration*` excludes all tests that reside in files
starting with `integration`.

Fixes: pytest-dev#3711
  • Loading branch information
fetzerch committed Feb 5, 2019
1 parent 2461a43 commit 5625bfc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Charles Cloud
Charnjit SiNGH (CCSJ)
Chris Lamb
Christian Boelsen
Christian Fetzer
Christian Theunert
Christian Tismer
Christopher Gilling
Expand Down
1 change: 1 addition & 0 deletions changelog/3711.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Unix shell-style wildcards to the ``--ignore`` parameter.
2 changes: 2 additions & 0 deletions doc/en/example/pythoncollection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions testing/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="""
Expand Down

0 comments on commit 5625bfc

Please sign in to comment.