File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed
pytest_github_actions_annotate_failures Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -327,6 +327,32 @@ def test_param(a, b):
327327 )
328328
329329
330+ @pytest .mark .skipif (
331+ version .parse ("9.0.0" ) > PYTEST_VERSION ,
332+ reason = "subtests are only supported in pytest 9+" ,
333+ )
334+ def test_annotation_subtest (testdir : pytest .Testdir ):
335+ testdir .makepyfile (
336+ """
337+ import pytest
338+ pytest_plugins = 'pytest_github_actions_annotate_failures'
339+
340+ def test(subtests):
341+ for i in range(5):
342+ with subtests.test(msg="custom message", i=i):
343+ assert i % 2 == 0
344+ """
345+ )
346+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
347+ result = testdir .runpytest_subprocess ()
348+ result .stderr .fnmatch_lines (
349+ [
350+ "::error file=test_annotation_subtest.py,line=7::test *custom message* *i=1*assert (1 %25 2) == 0*" ,
351+ "::error file=test_annotation_subtest.py,line=7::test *custom message* *i=3*assert (3 %25 2) == 0*" ,
352+ ]
353+ )
354+
355+
330356# Debugging / development tip:
331357# Add a breakpoint() to the place you are going to check,
332358# uncomment this example, and run it with:
Original file line number Diff line number Diff line change 1212if TYPE_CHECKING :
1313 from warnings import WarningMessage
1414
15- from _pytest .nodes import Item
16- from _pytest .reports import CollectReport
15+ from _pytest .reports import TestReport
1716
1817
1918# Reference:
2827PYTEST_VERSION = version .parse (pytest .__version__ )
2928
3029
31- @pytest .hookimpl (tryfirst = True , hookwrapper = True )
32- def pytest_runtest_makereport (item : Item , call ): # noqa: ARG001
33- # execute all other hooks to obtain the report object
34- outcome = yield
35- report : CollectReport = outcome .get_result ()
30+ @pytest .hookimpl (tryfirst = True )
31+ def pytest_runtest_logreport (report : TestReport ):
32+ """Handle test reporting for all pytest versions."""
3633
3734 # enable only in a workflow of GitHub Actions
3835 # ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
3936 if os .environ .get ("GITHUB_ACTIONS" ) != "true" :
4037 return
4138
39+ # Only handle failed tests in call phase
4240 if report .when == "call" and report .failed :
4341 filesystempath , lineno , _ = report .location
4442
You can’t perform that action at this time.
0 commit comments