|
| 1 | +import fnmatch |
1 | 2 | import sys |
2 | 3 | import pytest |
3 | | - |
| 4 | +import six |
4 | 5 |
|
5 | 6 | pytest_plugins = ["pytester"] |
6 | 7 | # In order to run meta-tests, see https://docs.pytest.org/en/latest/writing_plugins.html |
7 | 8 |
|
8 | 9 |
|
9 | | -@pytest.hookimpl(trylast=True) |
10 | | -def pytest_configure(config): |
| 10 | +def pytest_ignore_collect(path, config): |
11 | 11 | """ |
12 | | - In python 2, add |
| 12 | + In python 2, equivalent of adding |
13 | 13 |
|
14 | 14 | --ignore-glob='**/*py35*.py' |
15 | 15 |
|
| 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: |
16 | 20 | :param config: |
17 | 21 | :return: |
18 | 22 | """ |
19 | 23 | 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 |
28 | 53 |
|
29 | 54 |
|
30 | 55 | @pytest.fixture |
|
0 commit comments