Skip to content

Commit 17150cf

Browse files
authored
Fix compatibility with pytest 8.1 (allure-framework#795)
1 parent 20f51c8 commit 17150cf

File tree

2 files changed

+88
-22
lines changed

2 files changed

+88
-22
lines changed

.github/workflows/build.yaml

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,29 @@ on:
66
- master
77

88
jobs:
9-
changes:
10-
name: Collect file changes
9+
pytest-changes:
10+
name: Collect allure-pytest file changes
11+
runs-on: ubuntu-latest
12+
outputs:
13+
changed: ${{ steps.filter.outputs.allure-pytest }}
14+
steps:
15+
- uses: dorny/paths-filter@v3
16+
id: filter
17+
with:
18+
filters: |
19+
allure-pytest:
20+
- allure-pytest/**
21+
- allure-python-commons/**
22+
- allure-python-commons-test/**
23+
- tests/*.py
24+
- tests/allure_pytest/**
25+
other-changes:
26+
name: Collect file changes other than allure-pytest
1127
runs-on: ubuntu-latest
1228
outputs:
1329
packages: ${{ steps.filter.outputs.changes }}
1430
steps:
15-
- uses: dorny/paths-filter@v2
31+
- uses: dorny/paths-filter@v3
1632
id: filter
1733
with:
1834
filters: |
@@ -28,12 +44,6 @@ jobs:
2844
- allure-python-commons-test/**
2945
- tests/*.py
3046
- tests/allure_nose2/**
31-
allure-pytest:
32-
- allure-pytest/**
33-
- allure-python-commons/**
34-
- allure-python-commons-test/**
35-
- tests/*.py
36-
- tests/allure_pytest/**
3747
allure-pytest-bdd:
3848
- allure-pytest-bdd/**
3949
- allure-python-commons/**
@@ -53,7 +63,7 @@ jobs:
5363
name: Build commons
5464
runs-on: ubuntu-latest
5565
steps:
56-
- uses: actions/checkout@v3
66+
- uses: actions/checkout@v4
5767

5868
- name: Cache commons
5969
id: commons
@@ -68,13 +78,13 @@ jobs:
6878
python -m build allure-python-commons --outdir dist/ &&
6979
python -m build allure-python-commons-test --outdir dist/
7080

71-
linters:
81+
lint:
7282
name: Static check
7383
runs-on: ubuntu-latest
74-
needs: [commons, changes]
75-
if: ${{ needs.changes.outputs.packages != '[]' }}
84+
needs: [commons, pytest-changes, other-changes]
85+
if: ${{ needs.pytest-changes.outputs.changed || needs.other-changes.outputs.packages != '[]' }}
7686
steps:
77-
- uses: actions/checkout@v3
87+
- uses: actions/checkout@v4
7888

7989
- name: Set up Python
8090
uses: actions/setup-python@v4
@@ -87,23 +97,67 @@ jobs:
8797
- name: Linting the codebase
8898
run: poe linter
8999

90-
build:
91-
name: Test package
100+
test-pytest:
101+
name: Test allure-pytest
92102
runs-on: ubuntu-latest
93-
needs: [linters, commons, changes]
94-
if: ${{ needs.changes.outputs.packages != '[]' }}
103+
needs: [commons, pytest-changes]
104+
if: ${{ needs.pytest-changes.outputs.changed }}
95105
strategy:
96106
matrix:
97-
package: ${{ fromJSON(needs.changes.outputs.packages) }}
98107
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
108+
pytest-version: ["7.*", "8.*"]
109+
exclude:
110+
- python-version: "3.7"
111+
pytest-version: "8.*"
99112
env:
100113
TEST_TMP: /tmp
101114
ALLURE_INDENT_OUTPUT: yep
102115
steps:
103-
- uses: actions/checkout@v3
116+
- uses: actions/checkout@v4
104117

105118
- name: Set up Python ${{ matrix.python-version }}
106-
uses: actions/setup-python@v4
119+
uses: actions/setup-python@v5
120+
with:
121+
python-version: ${{ matrix.python-version }}
122+
123+
- name: Get commons from cache
124+
id: commons
125+
uses: actions/cache@v3
126+
with:
127+
path: dist/
128+
key: commons-${{ github.sha }}
129+
130+
- name: Install packages
131+
run: |
132+
pip install dist/allure-python-commons*.tar.gz \
133+
./allure-pytest \
134+
pytest==${{ matrix.pytest-version }} \
135+
-r ./requirements/testing.txt \
136+
-r ./requirements/testing/allure-pytest.txt
137+
138+
- name: Test allure-pytest
139+
working-directory: allure-pytest
140+
run: poe tests
141+
142+
test-others:
143+
name: Test packages other than allure-pytest
144+
runs-on: ubuntu-latest
145+
needs: [commons, other-changes]
146+
if: ${{ needs.other-changes.outputs.packages != '[]' }}
147+
strategy:
148+
matrix:
149+
package: ${{ fromJSON(needs.other-changes.outputs.packages) }}
150+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
151+
exclude:
152+
- package: allure-pytest
153+
env:
154+
TEST_TMP: /tmp
155+
ALLURE_INDENT_OUTPUT: yep
156+
steps:
157+
- uses: actions/checkout@v4
158+
159+
- name: Set up Python ${{ matrix.python-version }}
160+
uses: actions/setup-python@v5
107161
with:
108162
python-version: ${{ matrix.python-version }}
109163

allure-pytest/src/listener.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22
import doctest
3+
from packaging import version
4+
35
import allure_commons
46
from allure_commons.utils import now
57
from allure_commons.utils import uuid4
@@ -347,13 +349,23 @@ def _test_fixtures(item):
347349

348350
if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
349351
for name in item._request.fixturenames:
350-
fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)
352+
fixturedefs_pytest = _getfixturedefs(fixturemanager, name, item)
351353
if fixturedefs_pytest:
352354
fixturedefs.extend(fixturedefs_pytest)
353355

354356
return fixturedefs
355357

356358

359+
def _getfixturedefs(fixturemanager, name, item):
360+
# See pytest-dev/pytest#11785
361+
itemarg = item if __is_pytest8_1_or_greater() else item.nodeid
362+
return fixturemanager.getfixturedefs(name, itemarg)
363+
364+
365+
def __is_pytest8_1_or_greater():
366+
return version.parse(pytest.__version__) >= version.parse("8.1")
367+
368+
357369
def _exception_brokes_test(exception):
358370
return not isinstance(exception, (
359371
AssertionError,

0 commit comments

Comments
 (0)