Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ jobs:
run: python -m pip list

- name: Run tests
run: python -m pytest -n logical
run: >
python -m pytest -n logical
${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.12' && '--fail-soft-dependency-skips' || '' }}

- name: Save new cache
uses: actions/cache/save@v5
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr_pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ jobs:

- name: Run tests
# run the full test suit if a PR has the 'full pytest actions' label
run: python -m pytest -n logical --prtesting ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'full pytest actions') }}
run: >
python -m pytest -n logical
${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.12' && '--fail-soft-dependency-skips' || '' }}
--prtesting ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'full pytest actions') }}

doctests:
runs-on: ubuntu-24.04
Expand Down
40 changes: 40 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

__maintainer__ = ["MatthewMiddlehurst"]

import pytest


def _is_soft_dependency_skip(report):
if not report.skipped:
return False

skip_reason = (
report.longrepr[2]
if isinstance(report.longrepr, tuple)
else str(report.longrepr)
)
Comment on lines +20 to +24
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty evident what the function is doing as a whole but coud you leave a comment on why this is needed if possible

return "soft dependency" in skip_reason.lower()


def pytest_addoption(parser):
"""Pytest command line parser options adder."""
Expand All @@ -35,6 +49,32 @@ def pytest_addoption(parser):
"version."
),
)
parser.addoption(
"--fail-soft-dependency-skips",
action="store_true",
default=False,
help=(
"Fail tests skipped by soft dependency checks. Use only in environments "
"where soft dependencies are installed."
),
)


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
"""Turn soft dependency skips into failures when requested."""
outcome = yield
report = outcome.get_result()

if item.config.getoption(
"--fail-soft-dependency-skips"
) and _is_soft_dependency_skip(report):
report.outcome = "failed"
report.longrepr = (
"Test skipped because a soft dependency check failed while "
"--fail-soft-dependency-skips is enabled. "
f"Original skip reason: {report.longrepr}"
)


def pytest_configure(config):
Expand Down
Loading