Skip to content

Commit b541402

Browse files
author
Sylvain MARIE
committed
Fixed issue running the tests under pytest 2 and 3: ignore-glob was not known then.
1 parent 2291936 commit b541402

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

pytest_cases/tests/conftest.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
1+
import fnmatch
12
import sys
23
import pytest
3-
4+
import six
45

56
pytest_plugins = ["pytester"]
67
# In order to run meta-tests, see https://docs.pytest.org/en/latest/writing_plugins.html
78

89

9-
@pytest.hookimpl(trylast=True)
10-
def pytest_configure(config):
10+
def pytest_ignore_collect(path, config):
1111
"""
12-
In python 2, add
12+
In python 2, equivalent of adding
1313
1414
--ignore-glob='**/*py35*.py'
1515
16+
This method works even with old pytest 2 and 3.
17+
It was copied from recent pytest.main.pytest_ignore_collect
18+
19+
:param path:
1620
:param config:
1721
:return:
1822
"""
1923
if sys.version_info < (3, 5):
20-
print("Python < 3.5: ignoring test files containing 'py35'")
21-
OPT = ['**/*py35*.py']
22-
if config.option.ignore_glob is None:
23-
config.option.ignore_glob = OPT
24-
else:
25-
config.option.ignore_glob += OPT
26-
27-
# assert config.getoption('--ignore-glob') == OPT
24+
ignore_globs = ['**/*py35*.py']
25+
if any(
26+
fnmatch.fnmatch(six.text_type(path), six.text_type(glob))
27+
for glob in ignore_globs
28+
):
29+
return True
30+
31+
32+
# @pytest.hookimpl(trylast=True)
33+
# def pytest_configure(config):
34+
# """
35+
# In python 2, add
36+
#
37+
# --ignore-glob='**/*py35*.py'
38+
#
39+
# Unfortunately this is not supported in old pytests so we do this in pytest-collect
40+
#
41+
# :param config:
42+
# :return:
43+
# """
44+
# if sys.version_info < (3, 5):
45+
# print("Python < 3.5: ignoring test files containing 'py35'")
46+
# OPT = ['**/*py35*.py']
47+
# if config.option.ignore_glob is None:
48+
# config.option.ignore_glob = OPT
49+
# else:
50+
# config.option.ignore_glob += OPT
51+
#
52+
# assert config.getoption('--ignore-glob') == OPT
2853

2954

3055
@pytest.fixture

0 commit comments

Comments
 (0)