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
- # result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
12
+ # result.stderr.no_fnmatch_line() was 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
- def no_fnmatch_line (result , pattern ):
14
- if version .parse (pytest .__version__ ) >= version .parse ("5.3.0" ):
15
- result .stderr .no_fnmatch_line (pattern + "*" ,)
16
- else :
17
- assert pattern not in result .stderr .str ()
14
+ def no_fnmatch_line (result : pytest .RunResult , pattern : str ):
15
+ result .stderr .no_fnmatch_line (pattern + "*" )
18
16
19
17
20
- def test_annotation_succeed_no_output (testdir ):
18
+ def test_annotation_succeed_no_output (testdir : pytest . Testdir ):
21
19
testdir .makepyfile (
22
20
"""
23
21
import pytest
@@ -33,7 +31,7 @@ def test_success():
33
31
no_fnmatch_line (result , "::error file=test_annotation_succeed_no_output.py" )
34
32
35
33
36
- def test_annotation_pytest_error (testdir ):
34
+ def test_annotation_pytest_error (testdir : pytest . Testdir ):
37
35
testdir .makepyfile (
38
36
"""
39
37
import pytest
@@ -55,7 +53,7 @@ def test_error():
55
53
)
56
54
57
55
58
- def test_annotation_fail (testdir ):
56
+ def test_annotation_fail (testdir : pytest . Testdir ):
59
57
testdir .makepyfile (
60
58
"""
61
59
import pytest
@@ -68,11 +66,13 @@ def test_fail():
68
66
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
69
67
result = testdir .runpytest_subprocess ()
70
68
result .stderr .fnmatch_lines (
71
- ["::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,]
69
+ [
70
+ "::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,
71
+ ]
72
72
)
73
73
74
74
75
- def test_annotation_exception (testdir ):
75
+ def test_annotation_exception (testdir : pytest . Testdir ):
76
76
testdir .makepyfile (
77
77
"""
78
78
import pytest
@@ -86,11 +86,51 @@ def test_fail():
86
86
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
87
87
result = testdir .runpytest_subprocess ()
88
88
result .stderr .fnmatch_lines (
89
- ["::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,]
89
+ [
90
+ "::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,
91
+ ]
92
+ )
93
+
94
+
95
+ def test_annotation_warning (testdir : pytest .Testdir ):
96
+ testdir .makepyfile (
97
+ """
98
+ import warnings
99
+ import pytest
100
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
101
+
102
+ def test_warning():
103
+ warnings.warn('beware', Warning)
104
+ assert 1
105
+ """
90
106
)
107
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
108
+ result = testdir .runpytest_subprocess ()
109
+ result .stderr .fnmatch_lines (
110
+ [
111
+ "::warning file=test_annotation_warning.py,line=6::beware" ,
112
+ ]
113
+ )
114
+
115
+
116
+ def test_annotation_exclude_warnings (testdir : pytest .Testdir ):
117
+ testdir .makepyfile (
118
+ """
119
+ import warnings
120
+ import pytest
121
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
122
+
123
+ def test_warning():
124
+ warnings.warn('beware', Warning)
125
+ assert 1
126
+ """
127
+ )
128
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
129
+ result = testdir .runpytest_subprocess ("--exclude-warning-annotations" )
130
+ assert not result .stderr .lines
91
131
92
132
93
- def test_annotation_third_party_exception (testdir ):
133
+ def test_annotation_third_party_exception (testdir : pytest . Testdir ):
94
134
testdir .makepyfile (
95
135
my_module = """
96
136
def fn():
@@ -111,11 +151,43 @@ def test_fail():
111
151
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
112
152
result = testdir .runpytest_subprocess ()
113
153
result .stderr .fnmatch_lines (
114
- ["::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,]
154
+ [
155
+ "::error file=test_annotation_third_party_exception.py,line=6::test_fail*oops*" ,
156
+ ]
157
+ )
158
+
159
+
160
+ def test_annotation_third_party_warning (testdir : pytest .Testdir ):
161
+ testdir .makepyfile (
162
+ my_module = """
163
+ import warnings
164
+
165
+ def fn():
166
+ warnings.warn('beware', Warning)
167
+ """
168
+ )
169
+
170
+ testdir .makepyfile (
171
+ """
172
+ import pytest
173
+ from my_module import fn
174
+ pytest_plugins = 'pytest_github_actions_annotate_failures'
175
+
176
+ def test_warning():
177
+ fn()
178
+ """
179
+ )
180
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
181
+ result = testdir .runpytest_subprocess ()
182
+ result .stderr .fnmatch_lines (
183
+ # ["::warning file=test_annotation_third_party_warning.py,line=6::beware",]
184
+ [
185
+ "::warning file=my_module.py,line=4::beware" ,
186
+ ]
115
187
)
116
188
117
189
118
- def test_annotation_fail_disabled_outside_workflow (testdir ):
190
+ def test_annotation_fail_disabled_outside_workflow (testdir : pytest . Testdir ):
119
191
testdir .makepyfile (
120
192
"""
121
193
import pytest
@@ -132,7 +204,7 @@ def test_fail():
132
204
)
133
205
134
206
135
- def test_annotation_fail_cwd (testdir ):
207
+ def test_annotation_fail_cwd (testdir : pytest . Testdir ):
136
208
testdir .makepyfile (
137
209
"""
138
210
import pytest
@@ -148,11 +220,13 @@ def test_fail():
148
220
testdir .makefile (".ini" , pytest = "[pytest]\n testpaths=.." )
149
221
result = testdir .runpytest_subprocess ("--rootdir=foo" )
150
222
result .stderr .fnmatch_lines (
151
- ["::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,]
223
+ [
224
+ "::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,
225
+ ]
152
226
)
153
227
154
228
155
- def test_annotation_fail_runpath (testdir ):
229
+ def test_annotation_fail_runpath (testdir : pytest . Testdir ):
156
230
testdir .makepyfile (
157
231
"""
158
232
import pytest
@@ -166,11 +240,13 @@ def test_fail():
166
240
testdir .monkeypatch .setenv ("PYTEST_RUN_PATH" , "some_path" )
167
241
result = testdir .runpytest_subprocess ()
168
242
result .stderr .fnmatch_lines (
169
- ["::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,]
243
+ [
244
+ "::error file=some_path/test_annotation_fail_runpath.py,line=5::test_fail*assert 0*" ,
245
+ ]
170
246
)
171
247
172
248
173
- def test_annotation_long (testdir ):
249
+ def test_annotation_long (testdir : pytest . Testdir ):
174
250
testdir .makepyfile (
175
251
"""
176
252
import pytest
@@ -202,7 +278,7 @@ def test_fail():
202
278
no_fnmatch_line (result , "::*assert x += 1*" )
203
279
204
280
205
- def test_class_method (testdir ):
281
+ def test_class_method (testdir : pytest . Testdir ):
206
282
testdir .makepyfile (
207
283
"""
208
284
import pytest
@@ -224,7 +300,7 @@ def test_method(self):
224
300
no_fnmatch_line (result , "::*x = 1*" )
225
301
226
302
227
- def test_annotation_param (testdir ):
303
+ def test_annotation_param (testdir : pytest . Testdir ):
228
304
testdir .makepyfile (
229
305
"""
230
306
import pytest
0 commit comments