66import pytest
77
88
9+ PYTEST_VERSION = version .parse (pytest .__version__ )
910pytest_plugins = "pytester"
1011
1112
1213# result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
1314# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
1415def no_fnmatch_line (result , pattern ):
15- if version .parse (pytest .__version__ ) >= version .parse ("5.3.0" ):
16- result .stderr .no_fnmatch_line (pattern + "*" ,)
16+ if PYTEST_VERSION >= version .parse ("5.3.0" ):
17+ result .stderr .no_fnmatch_line (
18+ pattern + "*" ,
19+ )
1720 else :
1821 assert pattern not in result .stderr .str ()
1922
@@ -47,7 +50,9 @@ def test_fail():
4750 testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
4851 result = testdir .runpytest_subprocess ()
4952 result .stderr .fnmatch_lines (
50- ["::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,]
53+ [
54+ "::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,
55+ ]
5156 )
5257
5358
@@ -65,8 +70,56 @@ def test_fail():
6570 testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
6671 result = testdir .runpytest_subprocess ()
6772 result .stderr .fnmatch_lines (
68- ["::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,]
73+ [
74+ "::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,
75+ ]
76+ )
77+
78+
79+ @pytest .mark .skipif (
80+ PYTEST_VERSION < version .parse ("6.0.0" ),
81+ reason = "requires pytest 6.0.0" ,
82+ )
83+ def test_annotation_warning (testdir ):
84+ testdir .makepyfile (
85+ """
86+ import warnings
87+ import pytest
88+ pytest_plugins = 'pytest_github_actions_annotate_failures'
89+
90+ def test_warning():
91+ warnings.warn('beware', Warning)
92+ assert 1
93+ """
6994 )
95+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
96+ result = testdir .runpytest_subprocess ()
97+ result .stderr .fnmatch_lines (
98+ [
99+ "::warning file=test_annotation_warning.py,line=6::beware" ,
100+ ]
101+ )
102+
103+
104+ @pytest .mark .skipif (
105+ PYTEST_VERSION < version .parse ("6.0.0" ),
106+ reason = "requires pytest 6.0.0" ,
107+ )
108+ def test_annotation_exclude_warnings (testdir ):
109+ testdir .makepyfile (
110+ """
111+ import warnings
112+ import pytest
113+ pytest_plugins = 'pytest_github_actions_annotate_failures'
114+
115+ def test_warning():
116+ warnings.warn('beware', Warning)
117+ assert 1
118+ """
119+ )
120+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
121+ result = testdir .runpytest_subprocess ("--exclude-warnings" )
122+ assert not result .stderr .lines
70123
71124
72125def test_annotation_third_party_exception (testdir ):
@@ -90,7 +143,43 @@ def test_fail():
90143 testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
91144 result = testdir .runpytest_subprocess ()
92145 result .stderr .fnmatch_lines (
93- ["::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,]
146+ [
147+ "::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,
148+ ]
149+ )
150+
151+
152+ @pytest .mark .skipif (
153+ PYTEST_VERSION < version .parse ("6.0.0" ),
154+ reason = "requires pytest 6.0.0" ,
155+ )
156+ def test_annotation_third_party_warning (testdir ):
157+ testdir .makepyfile (
158+ my_module = """
159+ import warnings
160+
161+ def fn():
162+ warnings.warn('beware', Warning)
163+ """
164+ )
165+
166+ testdir .makepyfile (
167+ """
168+ import pytest
169+ from my_module import fn
170+ pytest_plugins = 'pytest_github_actions_annotate_failures'
171+
172+ def test_warning():
173+ fn()
174+ """
175+ )
176+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
177+ result = testdir .runpytest_subprocess ()
178+ result .stderr .fnmatch_lines (
179+ # ["::warning file=test_annotation_third_party_warning.py,line=6::beware",]
180+ [
181+ "::warning file=my_module.py,line=4::beware" ,
182+ ]
94183 )
95184
96185
@@ -127,7 +216,9 @@ def test_fail():
127216 testdir .makefile (".ini" , pytest = "[pytest]\n testpaths=.." )
128217 result = testdir .runpytest_subprocess ("--rootdir=foo" )
129218 result .stderr .fnmatch_lines (
130- ["::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,]
219+ [
220+ "::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,
221+ ]
131222 )
132223
133224
@@ -145,7 +236,9 @@ def test_fail():
145236 testdir .monkeypatch .setenv ("PYTEST_RUN_PATH" , "some_path" )
146237 result = testdir .runpytest_subprocess ()
147238 result .stderr .fnmatch_lines (
148- ["::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,]
239+ [
240+ "::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,
241+ ]
149242 )
150243
151244
0 commit comments