1- pytest_plugins = 'pytester'
2- import pytest
1+ # -*- coding: utf-8 -*-
32import os
3+
44from packaging import version
55
6+ import pytest
7+
8+
9+ pytest_plugins = "pytester"
10+
11+
612# result.stdout.no_fnmatch_line() is added to testdir on pytest 5.3.0
713# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
814def 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 + "*" ,)
1317 else :
1418 assert pattern not in result .stdout .str ()
1519
20+
1621def test_annotation_succeed_no_output (testdir ):
1722 testdir .makepyfile (
18- '''
23+ """
1924 import pytest
2025 pytest_plugins = 'pytest_github_actions_annotate_failures'
2126
2227 def test_success():
2328 assert 1
24- '''
29+ """
2530 )
26- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
31+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
2732 result = testdir .runpytest_subprocess ()
2833
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+
3036
3137def test_annotation_fail (testdir ):
3238 testdir .makepyfile (
33- '''
39+ """
3440 import pytest
3541 pytest_plugins = 'pytest_github_actions_annotate_failures'
3642
3743 def test_fail():
3844 assert 0
39- '''
45+ """
4046 )
41- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
47+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
4248 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+
4653
4754def test_annotation_exception (testdir ):
4855 testdir .makepyfile (
49- '''
56+ """
5057 import pytest
5158 pytest_plugins = 'pytest_github_actions_annotate_failures'
5259
5360 def test_fail():
5461 raise Exception('oops')
5562 assert 1
56- '''
63+ """
5764 )
58- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
65+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
5966 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+
6371
6472def test_annotation_fail_disabled_outside_workflow (testdir ):
6573 testdir .makepyfile (
66- '''
74+ """
6775 import pytest
6876 pytest_plugins = 'pytest_github_actions_annotate_failures'
6977
7078 def test_fail():
7179 assert 0
72- '''
80+ """
7381 )
74- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , '' )
82+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , "" )
7583 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+
7788
7889def test_annotation_fail_cwd (testdir ):
7990 testdir .makepyfile (
80- '''
91+ """
8192 import pytest
8293 pytest_plugins = 'pytest_github_actions_annotate_failures'
8394
8495 def test_fail():
8596 assert 0
86- '''
97+ """
8798 )
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+
96108
97109def test_annotation_long (testdir ):
98110 testdir .makepyfile (
99- '''
111+ """
100112 import pytest
101113 pytest_plugins = 'pytest_github_actions_annotate_failures'
102114
@@ -114,40 +126,43 @@ def test_fail():
114126 x += 1
115127
116128 assert f(x) == 3
117- '''
129+ """
118130 )
119- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
131+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
120132 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+
125140
126141def test_class_method (testdir ):
127142 testdir .makepyfile (
128- '''
143+ """
129144 import pytest
130145 pytest_plugins = 'pytest_github_actions_annotate_failures'
131146
132147 class TestClass(object):
133148 def test_method(self):
134149 x = 1
135150 assert x == 2
136- '''
151+ """
137152 )
138- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
153+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
139154 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*" )
146161
147162
148163def test_annotation_param (testdir ):
149164 testdir .makepyfile (
150- '''
165+ """
151166 import pytest
152167 pytest_plugins = 'pytest_github_actions_annotate_failures'
153168
@@ -159,13 +174,16 @@ def test_param(a, b):
159174 b += 1
160175
161176 assert a == b
162- '''
177+ """
163178 )
164- testdir .monkeypatch .setenv (' GITHUB_ACTIONS' , ' true' )
179+ testdir .monkeypatch .setenv (" GITHUB_ACTIONS" , " true" )
165180 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+
169187
170188# Debugging / development tip:
171189# Add a breakpoint() to the place you are going to check,
0 commit comments