From e57cb859f0d704c342d0625cbe82a5e24eebdfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Mon, 10 Nov 2025 00:01:26 -0600 Subject: [PATCH 1/2] Test with Pytest 9 --- tox.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tox.ini b/tox.ini index e65638c..e496bde 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,13 @@ [tox] envlist = +<<<<<<< HEAD py{38,39,310,311,312,313,314}-pytest{7,8} py{310,311,312,313,314}-pytest9 +||||||| parent of c3aa5cc (Test with Pytest 9) + py{38,39,310,311,312,313,314}-pytest{7,8} +======= + py{38,39,310,311,312,313,314}-pytest{7,8,9} +>>>>>>> c3aa5cc (Test with Pytest 9) [gh-actions] python = From caff56226b5979c59f8ba810da0360ce9027b84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Tue, 11 Nov 2025 14:19:50 -0600 Subject: [PATCH 2/2] Support Pytest 9+ subtests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edgar Ramírez Mondragón --- plugin_test.py | 26 +++++++++++++++++++ .../plugin.py | 14 +++++----- tox.ini | 6 ----- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/plugin_test.py b/plugin_test.py index c52315a..5231b29 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -351,6 +351,32 @@ def test_param(a, b): ) +@pytest.mark.skipif( + version.parse("9.0.0") > PYTEST_VERSION, + reason="subtests are only supported in pytest 9+", +) +def test_annotation_subtest(testdir: pytest.Testdir): + testdir.makepyfile( + """ + import pytest + pytest_plugins = 'pytest_github_actions_annotate_failures' + + def test(subtests): + for i in range(5): + with subtests.test(msg="custom message", i=i): + assert i % 2 == 0 + """ + ) + testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true") + result = testdir.runpytest_subprocess() + result.stderr.fnmatch_lines( + [ + "::error file=test_annotation_subtest.py,line=7::test *custom message* *i=1*assert (1 %25 2) == 0*", + "::error file=test_annotation_subtest.py,line=7::test *custom message* *i=3*assert (3 %25 2) == 0*", + ] + ) + + # Debugging / development tip: # Add a breakpoint() to the place you are going to check, # uncomment this example, and run it with: diff --git a/pytest_github_actions_annotate_failures/plugin.py b/pytest_github_actions_annotate_failures/plugin.py index bc18968..fc493eb 100644 --- a/pytest_github_actions_annotate_failures/plugin.py +++ b/pytest_github_actions_annotate_failures/plugin.py @@ -12,8 +12,7 @@ if TYPE_CHECKING: from warnings import WarningMessage - from _pytest.nodes import Item - from _pytest.reports import CollectReport + from _pytest.reports import TestReport # Reference: @@ -28,17 +27,16 @@ PYTEST_VERSION = version.parse(pytest.__version__) -@pytest.hookimpl(tryfirst=True, hookwrapper=True) -def pytest_runtest_makereport(item: Item, call): # noqa: ARG001 - # execute all other hooks to obtain the report object - outcome = yield - report: CollectReport = outcome.get_result() +@pytest.hookimpl(tryfirst=True) +def pytest_runtest_logreport(report: TestReport): + """Handle test reporting for all pytest versions.""" # enable only in a workflow of GitHub Actions # ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables if os.environ.get("GITHUB_ACTIONS") != "true": return + # Only handle failed tests in call phase if report.when == "call" and report.failed: filesystempath, lineno, _ = report.location @@ -46,7 +44,7 @@ def pytest_runtest_makereport(item: Item, call): # noqa: ARG001 # 0-index to 1-index lineno += 1 - longrepr = report.head_line or item.name + longrepr = report.head_line or "test" # get the error message and line number from the actual error if isinstance(report.longrepr, ExceptionRepr): diff --git a/tox.ini b/tox.ini index e496bde..e65638c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,7 @@ [tox] envlist = -<<<<<<< HEAD py{38,39,310,311,312,313,314}-pytest{7,8} py{310,311,312,313,314}-pytest9 -||||||| parent of c3aa5cc (Test with Pytest 9) - py{38,39,310,311,312,313,314}-pytest{7,8} -======= - py{38,39,310,311,312,313,314}-pytest{7,8,9} ->>>>>>> c3aa5cc (Test with Pytest 9) [gh-actions] python =