File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import copy
2
+ import os
3
+ import sys
4
+ from collections import OrderedDict
5
+ from typing import TYPE_CHECKING
6
+
1
7
import pytest
8
+
9
+
10
+ if TYPE_CHECKING :
11
+ from _pytest .reports import TestReport
12
+ # Reference:
13
+ # https://docs.pytest.org/en/latest/writing_plugins.html#hookwrapper-executing-around-other-hooks
14
+ # https://docs.pytest.org/en/latest/writing_plugins.html#hook-function-ordering-call-example
15
+ # https://docs.pytest.org/en/stable/reference.html#pytest.hookspec.pytest_runtest_makereport
16
+ #
17
+ # Inspired by:
18
+ # https://github.com/pytest-dev/pytest/blob/master/src/_pytest/terminal.py
19
+
20
+
21
+ @pytest .hookimpl (trylast = True )
22
+ def pytest_runtest_logreport (report : "TestReport" ):
23
+ """Add annotations of test failures or xpassed to github actions."""
24
+ # enable only in a workflow of GitHub Actions
25
+ if os .environ .get ("GITHUB_ACTIONS" ) is None :
26
+ return
27
+
28
+ if not report .when == "call" :
29
+ return
30
+
31
+ skip = not report .failed
32
+ message = "Test Failure."
33
+ if hasattr (report , "wasxfail" ) and report .outcome == "passed" :
34
+ skip = False
35
+ message = "Unexpected test success."
36
+
37
+ if skip :
38
+ return
39
+
40
+ print (
41
+ "\n ::error file={location[0]},line={location[1]},title={location[2]}::{message}" .format (
42
+ location = report .location , message = message
43
+ )
44
+ )
You can’t perform that action at this time.
0 commit comments