5
5
import pytest
6
6
from packaging import version
7
7
8
+ PYTEST_VERSION = version .parse (pytest .__version__ )
8
9
pytest_plugins = "pytester"
9
10
10
11
11
12
# result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
12
13
# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
13
14
def no_fnmatch_line (result , pattern ):
14
- if version .parse (pytest .__version__ ) >= version .parse ("5.3.0" ):
15
- result .stderr .no_fnmatch_line (pattern + "*" ,)
15
+ if version .parse ("5.3.0" ) <= PYTEST_VERSION :
16
+ result .stderr .no_fnmatch_line (
17
+ pattern + "*" ,
18
+ )
16
19
else :
17
20
assert pattern not in result .stderr .str ()
18
21
@@ -68,7 +71,9 @@ def test_fail():
68
71
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
69
72
result = testdir .runpytest_subprocess ()
70
73
result .stderr .fnmatch_lines (
71
- ["::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,]
74
+ [
75
+ "::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,
76
+ ]
72
77
)
73
78
74
79
@@ -86,8 +91,56 @@ def test_fail():
86
91
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
87
92
result = testdir .runpytest_subprocess ()
88
93
result .stderr .fnmatch_lines (
89
- ["::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,]
94
+ [
95
+ "::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,
96
+ ]
97
+ )
98
+
99
+
100
+ @pytest .mark .skipif (
101
+ version .parse ("6.0.0" ) > PYTEST_VERSION ,
102
+ reason = "requires pytest 6.0.0" ,
103
+ )
104
+ def test_annotation_warning (testdir ):
105
+ testdir .makepyfile (
106
+ """
107
+ import warnings
108
+ import pytest
109
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
110
+
111
+ def test_warning():
112
+ warnings.warn('beware', Warning)
113
+ assert 1
114
+ """
90
115
)
116
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
117
+ result = testdir .runpytest_subprocess ()
118
+ result .stderr .fnmatch_lines (
119
+ [
120
+ "::warning file=test_annotation_warning.py,line=6::beware" ,
121
+ ]
122
+ )
123
+
124
+
125
+ @pytest .mark .skipif (
126
+ version .parse ("6.0.0" ) > PYTEST_VERSION ,
127
+ reason = "requires pytest 6.0.0" ,
128
+ )
129
+ def test_annotation_exclude_warnings (testdir ):
130
+ testdir .makepyfile (
131
+ """
132
+ import warnings
133
+ import pytest
134
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
135
+
136
+ def test_warning():
137
+ warnings.warn('beware', Warning)
138
+ assert 1
139
+ """
140
+ )
141
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
142
+ result = testdir .runpytest_subprocess ("--exclude-warnings" )
143
+ assert not result .stderr .lines
91
144
92
145
93
146
def test_annotation_third_party_exception (testdir ):
@@ -111,7 +164,43 @@ def test_fail():
111
164
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
112
165
result = testdir .runpytest_subprocess ()
113
166
result .stderr .fnmatch_lines (
114
- ["::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,]
167
+ [
168
+ "::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,
169
+ ]
170
+ )
171
+
172
+
173
+ @pytest .mark .skipif (
174
+ version .parse ("6.0.0" ) > PYTEST_VERSION ,
175
+ reason = "requires pytest 6.0.0" ,
176
+ )
177
+ def test_annotation_third_party_warning (testdir ):
178
+ testdir .makepyfile (
179
+ my_module = """
180
+ import warnings
181
+
182
+ def fn():
183
+ warnings.warn('beware', Warning)
184
+ """
185
+ )
186
+
187
+ testdir .makepyfile (
188
+ """
189
+ import pytest
190
+ from my_module import fn
191
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
192
+
193
+ def test_warning():
194
+ fn()
195
+ """
196
+ )
197
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
198
+ result = testdir .runpytest_subprocess ()
199
+ result .stderr .fnmatch_lines (
200
+ # ["::warning file=test_annotation_third_party_warning.py,line=6::beware",]
201
+ [
202
+ "::warning file=my_module.py,line=4::beware" ,
203
+ ]
115
204
)
116
205
117
206
@@ -148,7 +237,9 @@ def test_fail():
148
237
testdir .makefile (".ini" , pytest = "[pytest]\n testpaths=.." )
149
238
result = testdir .runpytest_subprocess ("--rootdir=foo" )
150
239
result .stderr .fnmatch_lines (
151
- ["::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,]
240
+ [
241
+ "::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,
242
+ ]
152
243
)
153
244
154
245
@@ -166,7 +257,9 @@ def test_fail():
166
257
testdir .monkeypatch .setenv ("PYTEST_RUN_PATH" , "some_path" )
167
258
result = testdir .runpytest_subprocess ()
168
259
result .stderr .fnmatch_lines (
169
- ["::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,]
260
+ [
261
+ "::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,
262
+ ]
170
263
)
171
264
172
265
0 commit comments