6
6
import pytest
7
7
8
8
9
+ PYTEST_VERSION = version .parse (pytest .__version__ )
9
10
pytest_plugins = "pytester"
10
11
11
12
12
13
# result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
13
14
# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
14
15
def 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
+ )
17
20
else :
18
21
assert pattern not in result .stderr .str ()
19
22
@@ -47,7 +50,9 @@ def test_fail():
47
50
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
48
51
result = testdir .runpytest_subprocess ()
49
52
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
+ ]
51
56
)
52
57
53
58
@@ -65,8 +70,56 @@ def test_fail():
65
70
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
66
71
result = testdir .runpytest_subprocess ()
67
72
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
+ """
69
94
)
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
70
123
71
124
72
125
def test_annotation_third_party_exception (testdir ):
@@ -90,7 +143,43 @@ def test_fail():
90
143
testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
91
144
result = testdir .runpytest_subprocess ()
92
145
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
+ ]
94
183
)
95
184
96
185
@@ -127,7 +216,9 @@ def test_fail():
127
216
testdir .makefile (".ini" , pytest = "[pytest]\n testpaths=.." )
128
217
result = testdir .runpytest_subprocess ("--rootdir=foo" )
129
218
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
+ ]
131
222
)
132
223
133
224
@@ -145,7 +236,9 @@ def test_fail():
145
236
testdir .monkeypatch .setenv ("PYTEST_RUN_PATH" , "some_path" )
146
237
result = testdir .runpytest_subprocess ()
147
238
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
+ ]
149
242
)
150
243
151
244
0 commit comments