Skip to content

Commit 0b7f50f

Browse files
authored
Merge pull request #15 from pllim/pytest-8.1
MNT: Compat with pytest>=8
2 parents 44747eb + f43b264 commit 0b7f50f

File tree

8 files changed

+245
-86
lines changed

8 files changed

+245
-86
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions" # See documentation for possible values
9+
directory: ".github/workflows" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
if: ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) || contains(github.event.pull_request.labels.*.name, 'Build wheels'))
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717
with:
1818
fetch-depth: 0
19-
- uses: actions/setup-python@v2
19+
- uses: actions/setup-python@v5
2020
with:
2121
python-version: 3.8
2222

.github/workflows/python-tests.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Run unit tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
tags:
8+
- '*'
9+
workflow_dispatch:
10+
schedule:
11+
# Run every Thursday at 03:53 UTC
12+
- cron: 53 3 * * 4
13+
14+
jobs:
15+
tests:
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- os: ubuntu-latest
22+
python-version: 3.8
23+
toxenv: py38-test-pytestoldest
24+
- os: windows-latest
25+
python-version: 3.8
26+
toxenv: py38-test-pytest50
27+
- os: macos-latest
28+
python-version: 3.8
29+
toxenv: py38-test-pytest51
30+
- os: ubuntu-latest
31+
python-version: 3.8
32+
toxenv: py38-test-pytest52
33+
- os: windows-latest
34+
python-version: 3.8
35+
toxenv: py38-test-pytest53
36+
- os: ubuntu-latest
37+
python-version: 3.8
38+
toxenv: py38-test-pytest60
39+
- os: ubuntu-latest
40+
python-version: 3.9
41+
toxenv: py39-test-pytest61
42+
- os: ubuntu-latest
43+
python-version: 3.9
44+
toxenv: py39-test-pytest62
45+
- os: ubuntu-latest
46+
python-version: '3.10'
47+
toxenv: py310-test-pytest70
48+
- os: ubuntu-latest
49+
python-version: '3.10'
50+
toxenv: py310-test-pytest71
51+
- os: windows-latest
52+
python-version: '3.11'
53+
toxenv: py311-test-pytest72
54+
- os: ubuntu-latest
55+
python-version: '3.11'
56+
toxenv: py311-test-pytest73
57+
- os: ubuntu-latest
58+
python-version: '3.11'
59+
toxenv: py311-test-pytest74
60+
- os: ubuntu-latest
61+
python-version: '3.12'
62+
toxenv: py312-test-pytest80
63+
- os: macos-latest
64+
python-version: '3.12'
65+
toxenv: py312-test-pytest80
66+
- os: windows-latest
67+
python-version: '3.12'
68+
toxenv: py312-test-pytest80
69+
- os: macos-latest
70+
python-version: '3.11'
71+
toxenv: py311-test-pytestdev
72+
- os: windows-latest
73+
python-version: '3.11'
74+
toxenv: py311-test-pytestdev
75+
- os: ubuntu-latest
76+
python-version: '3.12'
77+
toxenv: py312-test-pytestdev
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
fetch-depth: 0
83+
- name: Set up Python ${{ matrix.python-version }}
84+
uses: actions/setup-python@v5
85+
with:
86+
python-version: ${{ matrix.python-version }}
87+
- name: Install Tox
88+
run: python -m pip install tox
89+
- name: Run Tox
90+
run: tox ${{ matrix.toxargs }} -v -e ${{ matrix.toxenv }}

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
0.1.3 (unreleased)
22
==================
33

4-
- No changes yet.
4+
- pytest 8.1 compatibility. [#15]
5+
6+
- Dropped Python 3.7 support. Minimum supported pytest is now 4.6. [#15]
57

68
0.1.2 (2022-12-11)
79
==================

azure-pipelines.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

pytest_filter_subpackage/plugin.py

Lines changed: 98 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
"""
77

88
import os
9+
910
import pytest
11+
from packaging.version import Version
12+
13+
_pytest_version = Version(pytest.__version__)
14+
PYTEST_GE_8_0 = any([_pytest_version.is_devrelease,
15+
_pytest_version.is_prerelease,
16+
_pytest_version >= Version('8.0')])
1017

1118

1219
def pytest_addoption(parser):
@@ -17,52 +24,106 @@ def pytest_addoption(parser):
1724
"string to specify multiple packages.")
1825

1926

20-
@pytest.hookimpl(tryfirst=True)
21-
def pytest_ignore_collect(path, config):
27+
if PYTEST_GE_8_0:
2228

23-
# NOTE: it is important that when we don't want to skip a file we return
24-
# None and not False - if we return False pytest will not call any other
25-
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.
29+
@pytest.hookimpl(tryfirst=True)
30+
def pytest_ignore_collect(collection_path, config):
2631

27-
# If the --package/-P option wasn't specified, don't do anything
28-
if config.getvalue('package') is None:
29-
return None
32+
# NOTE: it is important that when we don't want to skip a file we return
33+
# None and not False - if we return False pytest will not call any other
34+
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.
3035

31-
# If the path is a directory, never skip - just do the filtering on a file
32-
# by file basis.
33-
if os.path.isdir(path):
34-
return None
36+
# If the --package/-P option wasn't specified, don't do anything
37+
if config.getvalue('package') is None:
38+
return None
3539

36-
# Otherwise ignore filename for remainder of checks
37-
path = os.path.dirname(path)
40+
# If the path is a directory, never skip - just do the filtering on a file
41+
# by file basis.
42+
if collection_path.is_dir():
43+
return None
3844

39-
# Split path into components
40-
path = path.split(os.path.sep)
45+
# Otherwise ignore filename for remainder of checks
46+
path = str(collection_path.parent)
47+
48+
# Split path into components
49+
path = path.split(os.path.sep)
50+
51+
# Now cycle through and find the top level of the package - this is the
52+
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
53+
# to make sure that at least one of these files was found before escaping.
54+
found_prev = False
55+
for i in range(len(path), -1, -1):
56+
subpath = os.path.sep.join(path[:i])
57+
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
58+
os.path.exists(os.path.join(subpath, 'index.rst')))
59+
if found_prev and not found:
60+
break
61+
found_prev = found
4162

42-
# Now cycle through and find the top level of the package - this is the
43-
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
44-
# to make sure that at least one of these files was found before escaping.
45-
found_prev = False
46-
for i in range(len(path), -1, -1):
47-
subpath = os.path.sep.join(path[:i])
48-
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
49-
os.path.exists(os.path.join(subpath, 'index.rst')))
50-
if found_prev and not found:
51-
break
52-
found_prev = found
63+
subpackage_path = path[i+1:]
5364

54-
subpackage_path = path[i+1:]
65+
# Find selected sub-packages
66+
selected = config.getvalue('package').strip().split(',')
5567

56-
# Find selected sub-packages
57-
selected = config.getvalue('package').strip().split(',')
68+
# Finally, we check if this is one of the specified ones
69+
for subpackage_target in selected:
70+
for i, target in enumerate(subpackage_target.split('.')):
71+
if i >= len(subpackage_path) or target != subpackage_path[i]:
72+
break
5873

59-
# Finally, we check if this is one of the specified ones
60-
for subpackage_target in selected:
61-
for i, target in enumerate(subpackage_target.split('.')):
62-
if i >= len(subpackage_path) or target != subpackage_path[i]:
63-
break
74+
else:
75+
return None
76+
77+
return True
78+
79+
else:
80+
81+
@pytest.hookimpl(tryfirst=True)
82+
def pytest_ignore_collect(path, config):
6483

65-
else:
84+
# NOTE: it is important that when we don't want to skip a file we return
85+
# None and not False - if we return False pytest will not call any other
86+
# pytest_ignore_collect function in other plugins, e.g. pytest-doctestplus.
87+
88+
# If the --package/-P option wasn't specified, don't do anything
89+
if config.getvalue('package') is None:
90+
return None
91+
92+
# If the path is a directory, never skip - just do the filtering on a file
93+
# by file basis.
94+
if os.path.isdir(path):
6695
return None
6796

68-
return True
97+
# Otherwise ignore filename for remainder of checks
98+
path = os.path.dirname(path)
99+
100+
# Split path into components
101+
path = path.split(os.path.sep)
102+
103+
# Now cycle through and find the top level of the package - this is the
104+
# last one that contains an ``__init__.py`` or ``index.rst`` file. We need
105+
# to make sure that at least one of these files was found before escaping.
106+
found_prev = False
107+
for i in range(len(path), -1, -1):
108+
subpath = os.path.sep.join(path[:i])
109+
found = (os.path.exists(os.path.join(subpath, '__init__.py')) or
110+
os.path.exists(os.path.join(subpath, 'index.rst')))
111+
if found_prev and not found:
112+
break
113+
found_prev = found
114+
115+
subpackage_path = path[i+1:]
116+
117+
# Find selected sub-packages
118+
selected = config.getvalue('package').strip().split(',')
119+
120+
# Finally, we check if this is one of the specified ones
121+
for subpackage_target in selected:
122+
for i, target in enumerate(subpackage_target.split('.')):
123+
if i >= len(subpackage_path) or target != subpackage_path[i]:
124+
break
125+
126+
else:
127+
return None
128+
129+
return True

setup.cfg

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ url = https://github.com/astropy/pytest-filter-subpackage
44
author = The Astropy Developers
55
author_email = [email protected]
66
classifiers =
7-
Development Status :: 3 - Alpha
7+
Development Status :: 5 - Production/Stable
88
Framework :: Pytest
99
Intended Audience :: Developers
1010
License :: OSI Approved :: BSD License
1111
Operating System :: OS Independent
1212
Programming Language :: Python
1313
Programming Language :: Python :: 3
14-
Programming Language :: Python :: 3.7
1514
Programming Language :: Python :: 3.8
1615
Programming Language :: Python :: 3.9
1716
Programming Language :: Python :: 3.10
1817
Programming Language :: Python :: 3.11
18+
Programming Language :: Python :: 3.12
1919
Topic :: Software Development :: Testing
2020
Topic :: Utilities
2121
license = BSD
@@ -27,9 +27,9 @@ keywords = pytest, py.test
2727
[options]
2828
zip_safe = False
2929
packages = find:
30-
python_requires = >=3.7
30+
python_requires = >=3.8
3131
install_requires =
32-
pytest>=3.0
32+
pytest>=4.6
3333

3434
[options.entry_points]
3535
pytest11 =
@@ -42,13 +42,16 @@ test =
4242
pytest-cov
4343

4444
[tool:pytest]
45-
minversion = 3.0
45+
minversion = 4.6
4646
testpaths = tests pytest_filter_subpackage
4747
xfail_strict = true
4848
filterwarnings =
4949
error
5050
ignore:file format.*:UserWarning
5151
ignore:.*non-empty pattern match.*:FutureWarning
5252

53+
[flake8]
54+
max-line-length = 100
55+
5356
[bdist_wheel]
5457
universal = 1

0 commit comments

Comments
 (0)