Add ability to exclude files matching glob patterns with --ignore-glob

This adds the `--ignore-glob` option to allow Unix-style wildcards so
that `--ignore-glob=integration*` excludes all tests that reside in
files starting with `integration`.

Fixes: #3711
This commit is contained in:
Christian Fetzer
2019-02-05 17:19:24 +01:00
parent 2461a43e00
commit fc5d4654e5
5 changed files with 38 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ from __future__ import division
from __future__ import print_function
import contextlib
import fnmatch
import functools
import os
import pkgutil
@@ -117,6 +118,12 @@ def pytest_addoption(parser):
metavar="path",
help="ignore path during collection (multi-allowed).",
)
group.addoption(
"--ignore-glob",
action="append",
metavar="path",
help="ignore path pattern during collection (multi-allowed).",
)
group.addoption(
"--deselect",
action="append",
@@ -296,6 +303,17 @@ def pytest_ignore_collect(path, config):
if py.path.local(path) in ignore_paths:
return True
ignore_globs = []
excludeglobopt = config.getoption("ignore_glob")
if excludeglobopt:
ignore_globs.extend([py.path.local(x) for x in excludeglobopt])
if any(
fnmatch.fnmatch(six.text_type(path), six.text_type(glob))
for glob in ignore_globs
):
return True
allow_in_venv = config.getoption("collect_in_virtualenv")
if not allow_in_venv and _in_venv(path):
return True