1
- pytest_plugins = 'pytester'
2
- import pytest
1
+ # -*- coding: utf-8 -*-
3
2
import os
3
+
4
4
from packaging import version
5
5
6
+ import pytest
7
+
8
+
9
+ pytest_plugins = "pytester"
10
+
11
+
6
12
# result.stdout.no_fnmatch_line() is added to testdir on pytest 5.3.0
7
13
# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
8
14
def no_fnmatch_line (result , pattern ):
9
- if version .parse (pytest .__version__ ) >= version .parse ('5.3.0' ):
10
- result .stdout .no_fnmatch_line (
11
- pattern + '*' ,
12
- )
15
+ if version .parse (pytest .__version__ ) >= version .parse ("5.3.0" ):
16
+ result .stdout .no_fnmatch_line (pattern + "*" ,)
13
17
else :
14
18
assert pattern not in result .stdout .str ()
15
19
20
+
16
21
def test_annotation_succeed_no_output (testdir ):
17
22
testdir .makepyfile (
18
- '''
23
+ """
19
24
import pytest
20
25
pytest_plugins = 'pytest_github_actions_annotate_failures'
21
26
22
27
def test_success():
23
28
assert 1
24
- '''
29
+ """
25
30
)
26
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
31
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
27
32
result = testdir .runpytest_subprocess ()
28
33
29
- no_fnmatch_line (result , '::error file=test_annotation_succeed_no_output.py' )
34
+ no_fnmatch_line (result , "::error file=test_annotation_succeed_no_output.py" )
35
+
30
36
31
37
def test_annotation_fail (testdir ):
32
38
testdir .makepyfile (
33
- '''
39
+ """
34
40
import pytest
35
41
pytest_plugins = 'pytest_github_actions_annotate_failures'
36
42
37
43
def test_fail():
38
44
assert 0
39
- '''
45
+ """
40
46
)
41
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
47
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
42
48
result = testdir .runpytest_subprocess ()
43
- result .stdout .fnmatch_lines ([
44
- '::error file=test_annotation_fail.py,line=5::test_fail*assert 0*' ,
45
- ])
49
+ result .stdout .fnmatch_lines (
50
+ ["::error file=test_annotation_fail.py,line=5::test_fail*assert 0*" ,]
51
+ )
52
+
46
53
47
54
def test_annotation_exception (testdir ):
48
55
testdir .makepyfile (
49
- '''
56
+ """
50
57
import pytest
51
58
pytest_plugins = 'pytest_github_actions_annotate_failures'
52
59
53
60
def test_fail():
54
61
raise Exception('oops')
55
62
assert 1
56
- '''
63
+ """
57
64
)
58
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
65
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
59
66
result = testdir .runpytest_subprocess ()
60
- result .stdout .fnmatch_lines ([
61
- '::error file=test_annotation_exception.py,line=5::test_fail*oops*' ,
62
- ])
67
+ result .stdout .fnmatch_lines (
68
+ ["::error file=test_annotation_exception.py,line=5::test_fail*oops*" ,]
69
+ )
70
+
63
71
64
72
def test_annotation_fail_disabled_outside_workflow (testdir ):
65
73
testdir .makepyfile (
66
- '''
74
+ """
67
75
import pytest
68
76
pytest_plugins = 'pytest_github_actions_annotate_failures'
69
77
70
78
def test_fail():
71
79
assert 0
72
- '''
80
+ """
73
81
)
74
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , '' )
82
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , "" )
75
83
result = testdir .runpytest_subprocess ()
76
- no_fnmatch_line (result , '::error file=test_annotation_fail_disabled_outside_workflow.py*' )
84
+ no_fnmatch_line (
85
+ result , "::error file=test_annotation_fail_disabled_outside_workflow.py*"
86
+ )
87
+
77
88
78
89
def test_annotation_fail_cwd (testdir ):
79
90
testdir .makepyfile (
80
- '''
91
+ """
81
92
import pytest
82
93
pytest_plugins = 'pytest_github_actions_annotate_failures'
83
94
84
95
def test_fail():
85
96
assert 0
86
- '''
97
+ """
87
98
)
88
- testdir .monkeypatch .setenv ('GITHUB_ACTIONS' , 'true' )
89
- testdir .monkeypatch .setenv ('GITHUB_WORKSPACE' , os .path .dirname (str (testdir .tmpdir )))
90
- testdir .mkdir ('foo' )
91
- testdir .makefile ('.ini' , pytest = '[pytest]\n testpaths=..' )
92
- result = testdir .runpytest_subprocess ('--rootdir=foo' )
93
- result .stdout .fnmatch_lines ([
94
- '::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*' ,
95
- ])
99
+ testdir .monkeypatch .setenv ("GITHUB_ACTIONS" , "true" )
100
+ testdir .monkeypatch .setenv ("GITHUB_WORKSPACE" , os .path .dirname (str (testdir .tmpdir )))
101
+ testdir .mkdir ("foo" )
102
+ testdir .makefile (".ini" , pytest = "[pytest]\n testpaths=.." )
103
+ result = testdir .runpytest_subprocess ("--rootdir=foo" )
104
+ result .stdout .fnmatch_lines (
105
+ ["::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*" ,]
106
+ )
107
+
96
108
97
109
def test_annotation_long (testdir ):
98
110
testdir .makepyfile (
99
- '''
111
+ """
100
112
import pytest
101
113
pytest_plugins = 'pytest_github_actions_annotate_failures'
102
114
@@ -114,40 +126,43 @@ def test_fail():
114
126
x += 1
115
127
116
128
assert f(x) == 3
117
- '''
129
+ """
118
130
)
119
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
131
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
120
132
result = testdir .runpytest_subprocess ()
121
- result .stdout .fnmatch_lines ([
122
- '::error file=test_annotation_long.py,line=17::test_fail*assert 8 == 3*where 8 = f(8)*' ,
123
- ])
124
- no_fnmatch_line (result , '::*assert x += 1*' )
133
+ result .stdout .fnmatch_lines (
134
+ [
135
+ "::error file=test_annotation_long.py,line=17::test_fail*assert 8 == 3*where 8 = f(8)*" ,
136
+ ]
137
+ )
138
+ no_fnmatch_line (result , "::*assert x += 1*" )
139
+
125
140
126
141
def test_class_method (testdir ):
127
142
testdir .makepyfile (
128
- '''
143
+ """
129
144
import pytest
130
145
pytest_plugins = 'pytest_github_actions_annotate_failures'
131
146
132
147
class TestClass(object):
133
148
def test_method(self):
134
149
x = 1
135
150
assert x == 2
136
- '''
151
+ """
137
152
)
138
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
153
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
139
154
result = testdir .runpytest_subprocess ()
140
- result .stdout .fnmatch_lines ([
141
- '::error file=test_class_method.py,line=7::TestClass.test_method*assert 1 == 2*' ,
142
- ])
143
- no_fnmatch_line ( result , '::*x = 1*' )
144
-
145
-
155
+ result .stdout .fnmatch_lines (
156
+ [
157
+ "::error file=test_class_method.py,line=7::TestClass.test_method*assert 1 == 2*" ,
158
+ ]
159
+ )
160
+ no_fnmatch_line ( result , "::*x = 1*" )
146
161
147
162
148
163
def test_annotation_param (testdir ):
149
164
testdir .makepyfile (
150
- '''
165
+ """
151
166
import pytest
152
167
pytest_plugins = 'pytest_github_actions_annotate_failures'
153
168
@@ -159,13 +174,16 @@ def test_param(a, b):
159
174
b += 1
160
175
161
176
assert a == b
162
- '''
177
+ """
163
178
)
164
- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
179
+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
165
180
result = testdir .runpytest_subprocess ()
166
- result .stdout .fnmatch_lines ([
167
- '::error file=test_annotation_param.py,line=11::test_param?other?1*assert 2 == 3*' ,
168
- ])
181
+ result .stdout .fnmatch_lines (
182
+ [
183
+ "::error file=test_annotation_param.py,line=11::test_param?other?1*assert 2 == 3*" ,
184
+ ]
185
+ )
186
+
169
187
170
188
# Debugging / development tip:
171
189
# Add a breakpoint() to the place you are going to check,
0 commit comments