Skip to content

Commit 7b7f5a9

Browse files
committed
Support latest pytest versions
1 parent 9779f96 commit 7b7f5a9

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ on:
44
push:
55
branches:
66
- main
7+
- 2.2.x
78
tags:
89
- '*'
910

1011
pull_request:
1112
branches:
1213
- main
1314

15+
workflow_dispatch:
16+
1417
jobs:
1518
build:
16-
runs-on: ubuntu-latest
19+
runs-on: ${{ (matrix.python == '3.7' || matrix.python == '3.8') && 'ubuntu-22.04' || 'ubuntu-latest' }}
1720

1821
strategy:
1922
matrix:
20-
python: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3.9', 'pypy3.10']
23+
python: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3.9', 'pypy3.10', 'pypy3.11']
2124

2225
steps:
2326
- uses: actions/checkout@v3
@@ -40,31 +43,35 @@ jobs:
4043

4144
- name: Test with Python 3.8
4245
if: matrix.python == '3.8'
43-
run: tox run -x "tox.envlist=py38-pytest{4,5,60,61,62,70,71,72,73,74,80}"
46+
run: tox run -x "tox.envlist=py38-pytest{4,5,60,61,62,70,71,72,73,74,80,81,82,83}"
4447

4548
- name: Test with Python 3.9
4649
if: matrix.python == '3.9'
47-
run: tox run -x "tox.envlist=py39-pytest{4,5,60,61,62,70,71,72,73,74,80}"
50+
run: tox run -x "tox.envlist=py39-pytest{4,5,60,61,62,70,71,72,73,74,80,81,82,83,84}"
4851

4952
- name: Test with Python 3.10
5053
if: matrix.python == '3.10'
51-
run: tox run -x "tox.envlist=py310-pytest{70,71,72,73,74,80}"
54+
run: tox run -x "tox.envlist=py310-pytest{70,71,72,73,74,80,81,82,83,84}"
5255

5356
- name: Test with Python 3.11
5457
if: matrix.python == '3.11'
55-
run: tox run -x "tox.envlist=spy311-pytest{73,74,80}"
58+
run: tox run -x "tox.envlist=spy311-pytest{73,74,80,81,82,83,84}"
5659

5760
- name: Test with Python 3.12
5861
if: matrix.python == '3.12'
59-
run: tox run -x "tox.envlist=spy312-pytest{74,80}"
62+
run: tox run -x "tox.envlist=spy312-pytest{74,80,81,82,83,84}"
6063

6164
- name: Test with PyPy 3.9
6265
if: matrix.python == 'pypy3.9'
6366
run: tox run -x "tox.envlist=pypy39-pytest{4,5,60,61,62,70,71,72,73,74}"
6467

6568
- name: Test with PyPy 3.10
6669
if: matrix.python == 'pypy3.10'
67-
run: tox run -x "tox.envlist=pypy310-pytest{70,71,72,73,74,80}"
70+
run: tox run -x "tox.envlist=pypy310-pytest{70,71,72,73,74,80,81,82,83,84}"
71+
72+
- name: Test with PyPy 3.11
73+
if: matrix.python == 'pypy3.11'
74+
run: tox run -x "tox.envlist=pypy311-pytest{73,74,80,81,82,83,84}"
6875

6976
- name: Linting with Flake8
7077
if: matrix.python == '3.11'
@@ -88,7 +95,7 @@ jobs:
8895

8996
- uses: actions/setup-python@v4
9097
with:
91-
python-version: '3.10'
98+
python-version: '3.12'
9299

93100
- name: Install dependencies
94101
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Running pytest will show that the plugin is loaded:
2626
```sh
2727
$ pytest
2828
...
29-
plugins: describe-2.2.0
29+
plugins: describe-2.2.1
3030
...
3131
```
3232

pytest_describe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = ['behaves_like']
44

5-
__version__ = '2.2.0'
5+
__version__ = '2.2.1'

pytest_describe/plugin.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@
55
import pytest
66

77

8-
PYTEST_GTE_7_0 = getattr(pytest, 'version_tuple', (0, 0)) >= (7, 0)
8+
try:
9+
from _pytest.fixtures import FixtureFunctionDefinition
10+
except ImportError: # pragma: no cover (pytest < 8.4)
11+
def is_function_or_fixture(obj):
12+
return isinstance(obj, types.FunctionType)
13+
14+
def is_fixture_function_definition(obj):
15+
return hasattr(obj, '_pytestfixturefunction')
16+
else:
17+
def is_function_or_fixture(obj):
18+
return isinstance(obj, (types.FunctionType, FixtureFunctionDefinition))
19+
20+
def is_fixture_function_definition(obj):
21+
return isinstance(obj, FixtureFunctionDefinition)
22+
23+
24+
PYTEST_GTE_7_0 = getattr(pytest, 'version_tuple', (4, 0)) >= (7, 0)
925
PYTEST_GTE_5_4 = PYTEST_GTE_7_0 or hasattr(pytest.Collector, 'from_parent')
1026

1127

@@ -50,14 +66,14 @@ def evaluate_shared_behavior(func):
5066
except AttributeError:
5167
shared_functions = {}
5268
for name, obj in trace_function(func).items():
53-
# Only functions are relevant here
54-
if not isinstance(obj, types.FunctionType):
69+
# Only functions and fixtures are relevant here
70+
if not is_function_or_fixture(obj):
5571
continue
5672

57-
# Mangle names of imported functions, except fixtures because we
58-
# want fixtures to be overridden in the block that's importing the
59-
# behavior.
60-
if not hasattr(obj, '_pytestfixturefunction'):
73+
# Mangle names of imported functions, except fixtures
74+
# because we want fixtures to be overridden in the block
75+
# that's importing the behavior.
76+
if not is_fixture_function_definition(obj):
6177
name = obj._mangled_name = f"{func.__name__}::{name}"
6278

6379
shared_functions[name] = obj

tox.ini

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py37-pytest{4,5,60,61,62,70,71,72,73,74},py{38,39,py39}-pytest{4,5,60,61,62,70,71,72,73,74,80},py{310,py310}-pytest{70,71,72,73,74,80},py311-pytest{73,74,80,-latest},py312-pytest{74,80,-latest},flake8,coverage
2+
envlist = py37-pytest{4,5,60,61,62,70,71,72,73,74},py38-pytest{4,5,60,61,62,70,71,72,73,74,80,81,82,83},py{39,py39}-pytest{4,5,60,61,62,70,71,72,73,74,80,81,82,83,84,-latest},py{310,py310}-pytest{70,71,72,73,74,80,81,82,83,84,-latest},py{311,py311}-pytest{73,74,80,81,82,83,84,-latest},py312-pytest{74,80,81,82,83,84,-latest},flake8,coverage
33

44
[testenv]
55
basepython =
@@ -11,6 +11,7 @@ basepython =
1111
py312: python3.12
1212
pypy39: pypy3.9
1313
pypy310: pypy3.10
14+
pypy311: pypy3.11
1415
deps =
1516
pytest4: pytest>=4.6,<5.0
1617
pytest5: pytest>=5.4,<5.5
@@ -23,18 +24,22 @@ deps =
2324
pytest73: pytest>=7.3,<7.4
2425
pytest74: pytest>=7.4,<7.5
2526
pytest80: pytest>=8.0,<8.1
27+
pytest81: pytest>=8.1,<8.2
28+
pytest82: pytest>=8.2,<8.3
29+
pytest83: pytest>=8.3,<8.4
30+
pytest84: pytest>=8.4,<8.5
2631
pytest-latest: pytest
2732
pytest-main: git+https://github.com/pytest-dev/pytest.git@main
2833
commands = pytest test {posargs}
2934

3035
[testenv:flake8]
31-
basepython = python3.11
36+
basepython = python3.12
3237
deps = flake8>=7,<8
3338
commands =
3439
flake8 pytest_describe test setup.py
3540

3641
[testenv:coverage]
37-
basepython = python3.11
42+
basepython = python3.12
3843
deps =
3944
coverage
4045
pytest

0 commit comments

Comments
 (0)