Skip to content

Commit a777d6b

Browse files
Fix compatibility with Pytest 8.4+ (#188)
* Fix test suite saltstack/salt#67973 * Fix compatibility with Pytest 8.4+ * Fix Docs CI to use supported runner --------- Co-authored-by: scriptautomate-bc <204508229+scriptautomate-bc@users.noreply.github.com>
1 parent fbe127a commit a777d6b

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
pre-commit run --show-diff-on-failure --color=always --all-files
4343
4444
Docs:
45-
runs-on: ubuntu-20.04
45+
runs-on: ubuntu-22.04
4646
needs: Pre-Commit
4747

4848
timeout-minutes: 10

changelog/187.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed compatibility with Pytest 8.4+

noxfile.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,16 @@ def tests(session):
156156
constraints = [*salt_requirements, *pytest_requirements]
157157
with tempfile.NamedTemporaryFile(
158158
"w", prefix="reqs-constraints-", suffix=".txt", delete=False
159-
) as tfile:
159+
) as tfile, tempfile.NamedTemporaryFile(
160+
"w", prefix="build-constraints-", suffix=".txt", delete=False
161+
) as build_constraints:
160162
with open(tfile.name, "w", encoding="utf-8") as wfh:
161163
for req in constraints:
162164
wfh.write(f"{req}\n")
165+
with open(build_constraints.name, "w", encoding="utf-8") as wfh:
166+
wfh.write("setuptools<75.6.0\n")
167+
base_env = {"PIP_CONSTRAINT": build_constraints.name}
168+
env.update(base_env)
163169
if system_service:
164170
if pytest_requirements:
165171
session.install(
@@ -175,7 +181,9 @@ def tests(session):
175181
silent=PIP_INSTALL_SILENT,
176182
env=env,
177183
)
178-
session.install("-c", tfile.name, "-e", ".", silent=PIP_INSTALL_SILENT)
184+
session.install(
185+
"-c", tfile.name, "-e", ".", silent=PIP_INSTALL_SILENT, env=base_env
186+
)
179187
session.install(
180188
"-c",
181189
tfile.name,

src/saltfactories/plugins/loader.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
from saltfactories.utils.loader import LoaderModuleMock
99

10+
try:
11+
from _pytest.fixtures import FixtureFunctionDefinition
12+
except ImportError:
13+
FixtureFunctionDefinition = None
14+
1015
log = logging.getLogger(__name__)
1116

1217

@@ -30,17 +35,15 @@ def pytest_collection_modifyitems(items):
3035
for typo in typos:
3136
try:
3237
fixture = getattr(item.module, typo)
33-
try:
34-
fixture._pytestfixturefunction # pylint: disable=pointless-statement
35-
msg = (
36-
f"The module {item.module} defines a '{typo}' fixture but the correct fixture "
37-
"name is 'configure_loader_modules'"
38-
)
39-
raise RuntimeError(msg)
40-
except AttributeError:
38+
if not _verify_fixture(fixture):
4139
# It's a regular function?!
4240
# Carry on
43-
pass
41+
continue
42+
msg = (
43+
f"The module {item.module} defines a '{typo}' fixture but the correct fixture "
44+
"name is 'configure_loader_modules'"
45+
)
46+
raise RuntimeError(msg)
4447
except AttributeError:
4548
# The test module does not define a function with the typo as the name. Good.
4649
pass
@@ -52,15 +55,21 @@ def pytest_collection_modifyitems(items):
5255
continue
5356
else:
5457
# The test module defines a `configure_loader_modules` function. Is it a fixture?
55-
try:
56-
fixture._pytestfixturefunction
57-
except AttributeError:
58-
# It's not a fixture, raise an error
59-
msg = (
60-
f"The module {item.module} defines a 'configure_loader_modules' function but "
61-
"that function is not a fixture"
62-
)
63-
raise RuntimeError(msg) from None
58+
if _verify_fixture(fixture):
59+
continue
60+
# It's not a fixture, raise an error
61+
msg = (
62+
f"The module {item.module} defines a 'configure_loader_modules' function but "
63+
"that function is not a fixture"
64+
)
65+
raise RuntimeError(msg) from None
66+
67+
68+
def _verify_fixture(func):
69+
if FixtureFunctionDefinition is not None:
70+
# pytest 8.4+
71+
return isinstance(func, FixtureFunctionDefinition)
72+
return hasattr(func, "_pytestfixturefunction")
6473

6574

6675
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)