Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
pre-commit run --show-diff-on-failure --color=always --all-files

Docs:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: Pre-Commit

timeout-minutes: 10
Expand Down
1 change: 1 addition & 0 deletions changelog/187.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed compatibility with Pytest 8.4+
12 changes: 10 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ def tests(session):
constraints = [*salt_requirements, *pytest_requirements]
with tempfile.NamedTemporaryFile(
"w", prefix="reqs-constraints-", suffix=".txt", delete=False
) as tfile:
) as tfile, tempfile.NamedTemporaryFile(
"w", prefix="build-constraints-", suffix=".txt", delete=False
) as build_constraints:
with open(tfile.name, "w", encoding="utf-8") as wfh:
for req in constraints:
wfh.write(f"{req}\n")
with open(build_constraints.name, "w", encoding="utf-8") as wfh:
wfh.write("setuptools<75.6.0\n")
base_env = {"PIP_CONSTRAINT": build_constraints.name}
env.update(base_env)
if system_service:
if pytest_requirements:
session.install(
Expand All @@ -175,7 +181,9 @@ def tests(session):
silent=PIP_INSTALL_SILENT,
env=env,
)
session.install("-c", tfile.name, "-e", ".", silent=PIP_INSTALL_SILENT)
session.install(
"-c", tfile.name, "-e", ".", silent=PIP_INSTALL_SILENT, env=base_env
)
session.install(
"-c",
tfile.name,
Expand Down
45 changes: 27 additions & 18 deletions src/saltfactories/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

from saltfactories.utils.loader import LoaderModuleMock

try:
from _pytest.fixtures import FixtureFunctionDefinition
except ImportError:
FixtureFunctionDefinition = None

log = logging.getLogger(__name__)


Expand All @@ -30,17 +35,15 @@ def pytest_collection_modifyitems(items):
for typo in typos:
try:
fixture = getattr(item.module, typo)
try:
fixture._pytestfixturefunction # pylint: disable=pointless-statement
msg = (
f"The module {item.module} defines a '{typo}' fixture but the correct fixture "
"name is 'configure_loader_modules'"
)
raise RuntimeError(msg)
except AttributeError:
if not _verify_fixture(fixture):
# It's a regular function?!
# Carry on
pass
continue
msg = (
f"The module {item.module} defines a '{typo}' fixture but the correct fixture "
"name is 'configure_loader_modules'"
)
raise RuntimeError(msg)
except AttributeError:
# The test module does not define a function with the typo as the name. Good.
pass
Expand All @@ -52,15 +55,21 @@ def pytest_collection_modifyitems(items):
continue
else:
# The test module defines a `configure_loader_modules` function. Is it a fixture?
try:
fixture._pytestfixturefunction
except AttributeError:
# It's not a fixture, raise an error
msg = (
f"The module {item.module} defines a 'configure_loader_modules' function but "
"that function is not a fixture"
)
raise RuntimeError(msg) from None
if _verify_fixture(fixture):
continue
# It's not a fixture, raise an error
msg = (
f"The module {item.module} defines a 'configure_loader_modules' function but "
"that function is not a fixture"
)
raise RuntimeError(msg) from None


def _verify_fixture(func):
if FixtureFunctionDefinition is not None:
# pytest 8.4+
return isinstance(func, FixtureFunctionDefinition)
return hasattr(func, "_pytestfixturefunction")


@pytest.fixture(autouse=True)
Expand Down
Loading