Skip to content

Commit 7905f26

Browse files
committed
format: apply suggestions
1 parent 67bb654 commit 7905f26

File tree

3 files changed

+94
-74
lines changed

3 files changed

+94
-74
lines changed

plugin_test.py

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,114 @@
1-
pytest_plugins = 'pytester'
2-
import pytest
1+
# -*- coding: utf-8 -*-
32
import os
3+
44
from 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
814
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 + "*",)
1317
else:
1418
assert pattern not in result.stdout.str()
1519

20+
1621
def 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

3137
def 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

4754
def 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

6472
def 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

7889
def 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]\ntestpaths=..')
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]\ntestpaths=..")
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

97109
def 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

126141
def 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

148163
def 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,

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# -*- coding: utf-8 -*-
12
from __future__ import print_function
3+
24
import os
3-
import pytest
45
from collections import OrderedDict
56

7+
import pytest
8+
69
# Reference:
710
# https://docs.pytest.org/en/latest/writing_plugins.html#hookwrapper-executing-around-other-hooks
811
# https://docs.pytest.org/en/latest/writing_plugins.html#hook-function-ordering-call-example
@@ -11,6 +14,7 @@
1114
# Inspired by:
1215
# https://github.com/pytest-dev/pytest/blob/master/src/_pytest/terminal.py
1316

17+
1418
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
1519
def pytest_runtest_makereport(item, call):
1620
# execute all other hooks to obtain the report object
@@ -19,25 +23,24 @@ def pytest_runtest_makereport(item, call):
1923

2024
# enable only in a workflow of GitHub Actions
2125
# ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
22-
if os.environ.get('GITHUB_ACTIONS') != 'true':
26+
if os.environ.get("GITHUB_ACTIONS") != "true":
2327
return
2428

2529
if report.when == "call" and report.failed:
2630
# collect information to be annotated
2731
filesystempath, lineno, _ = report.location
2832

2933
# try to convert to absolute path in GitHub Actions
30-
workspace = os.environ.get('GITHUB_WORKSPACE')
34+
workspace = os.environ.get("GITHUB_WORKSPACE")
3135
if workspace:
3236
full_path = os.path.abspath(filesystempath)
3337
rel_path = os.path.relpath(full_path, workspace)
34-
if not rel_path.startswith('..'):
38+
if not rel_path.startswith(".."):
3539
filesystempath = rel_path
3640

3741
# 0-index to 1-index
3842
lineno += 1
3943

40-
4144
# get the name of the current failed test, with parametrize info
4245
longrepr = report.head_line or item.name
4346

@@ -59,13 +62,14 @@ def _error_workflow_command(filesystempath, lineno, longrepr):
5962
if lineno is not None:
6063
details_dict["line"] = lineno
6164

62-
details = ",".join("{}={}".format(k,v) for k,v in details_dict.items())
65+
details = ",".join("{}={}".format(k, v) for k, v in details_dict.items())
6366

6467
if longrepr is None:
65-
return '\n::error {}'.format(details)
68+
return "\n::error {}".format(details)
6669
else:
6770
longrepr = _escape(longrepr)
68-
return '\n::error {}::{}'.format(details, longrepr)
71+
return "\n::error {}::{}".format(details, longrepr)
72+
6973

7074
def _escape(s):
71-
return s.replace('%', '%25').replace('\r', '%0D').replace('\n', '%0A')
75+
return s.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")

setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from setuptools import setup, find_packages
1+
# -*- coding: utf-8 -*-
2+
from setuptools import find_packages, setup
3+
24

35
with open("./README.md") as f:
46
long_description = f.read()
@@ -13,16 +15,12 @@
1315
author_email="[email protected]",
1416
url="https://github.com/utgwkk/pytest-github-actions-annotate-failures",
1517
license="MIT",
16-
classifiers=[
17-
"Framework :: Pytest",
18-
],
18+
classifiers=["Framework :: Pytest",],
1919
packages=find_packages(),
2020
entry_points={
2121
"pytest11": [
2222
"pytest_github_actions_annotate_failures = pytest_github_actions_annotate_failures.plugin",
2323
],
2424
},
25-
install_requires=[
26-
"pytest>=4.0.0",
27-
],
25+
install_requires=["pytest>=4.0.0",],
2826
)

0 commit comments

Comments
 (0)