Skip to content

ci: fix conftest compatibility with pytest 8.1 #8579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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
31 changes: 24 additions & 7 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def pytest_configure(config):
# DEV: We can only ignore folders/modules, we cannot ignore individual files
# DEV: We must wrap with `@pytest.mark.hookwrapper` to inherit from default (e.g. honor `--ignore`)
# https://github.com/pytest-dev/pytest/issues/846#issuecomment-122129189
@pytest.hookimpl(hookwrapper=True)
def pytest_ignore_collect(path, config):
def _pytest_ignore_collect(path, outcome):
"""
Skip directories defining a required minimum Python version

Expand All @@ -82,11 +81,6 @@ def pytest_ignore_collect(path, config):
Python 3.5: Collect
Python 3.6: Collect
"""
# Execute original behavior first
# DEV: We need to set `outcome.force_result(True)` if we need to override
# these results and skip this directory
outcome = yield

# Was not ignored by default behavior
if not outcome.get_result():
# DEV: `path` is a `LocalPath`
Expand All @@ -105,6 +99,29 @@ def pytest_ignore_collect(path, config):
outcome.force_result(True)


_pytest_version = pytest.__version__
PYTEST_GTE_7 = int(_pytest_version.split(".")[0]) >= 7
if PYTEST_GTE_7:

@pytest.hookimpl(hookwrapper=True)
def pytest_ignore_collect(collection_path, config):
# Execute original behavior first
# DEV: We need to set `outcome.force_result(True)` if we need to override
# these results and skip this directory
outcome = yield
_pytest_ignore_collect(collection_path, outcome)

else:

@pytest.hookimpl(hookwrapper=True)
def pytest_ignore_collect(path, config):
# Execute original behavior first
# DEV: We need to set `outcome.force_result(True)` if we need to override
# these results and skip this directory
outcome = yield
_pytest_ignore_collect(path, outcome)


@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# Attach the outcome of the test (failed, passed, skipped) to the test node so that fixtures
Expand Down