Skip to content

Commit dcd7662

Browse files
authored
Merge pull request #22 from yihuang/usestderr
Fix #21: stdout is captured by pytest-xdist
2 parents fe94e4b + 3caf28e commit dcd7662

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

plugin_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
pytest_plugins = "pytester"
1010

1111

12-
# result.stdout.no_fnmatch_line() is added to testdir on pytest 5.3.0
12+
# result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
1313
# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
1414
def no_fnmatch_line(result, pattern):
1515
if version.parse(pytest.__version__) >= version.parse("5.3.0"):
16-
result.stdout.no_fnmatch_line(pattern + "*",)
16+
result.stderr.no_fnmatch_line(pattern + "*",)
1717
else:
18-
assert pattern not in result.stdout.str()
18+
assert pattern not in result.stderr.str()
1919

2020

2121
def test_annotation_succeed_no_output(testdir):
@@ -46,7 +46,7 @@ def test_fail():
4646
)
4747
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
4848
result = testdir.runpytest_subprocess()
49-
result.stdout.fnmatch_lines(
49+
result.stderr.fnmatch_lines(
5050
["::error file=test_annotation_fail.py,line=5::test_fail*assert 0*",]
5151
)
5252

@@ -64,7 +64,7 @@ def test_fail():
6464
)
6565
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
6666
result = testdir.runpytest_subprocess()
67-
result.stdout.fnmatch_lines(
67+
result.stderr.fnmatch_lines(
6868
["::error file=test_annotation_exception.py,line=5::test_fail*oops*",]
6969
)
7070

@@ -101,7 +101,7 @@ def test_fail():
101101
testdir.mkdir("foo")
102102
testdir.makefile(".ini", pytest="[pytest]\ntestpaths=..")
103103
result = testdir.runpytest_subprocess("--rootdir=foo")
104-
result.stdout.fnmatch_lines(
104+
result.stderr.fnmatch_lines(
105105
["::error file=test_annotation_fail_cwd.py,line=5::test_fail*assert 0*",]
106106
)
107107

@@ -130,7 +130,7 @@ def test_fail():
130130
)
131131
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
132132
result = testdir.runpytest_subprocess()
133-
result.stdout.fnmatch_lines(
133+
result.stderr.fnmatch_lines(
134134
[
135135
"::error file=test_annotation_long.py,line=17::test_fail*assert 8 == 3*where 8 = f(8)*",
136136
]
@@ -152,7 +152,7 @@ def test_method(self):
152152
)
153153
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
154154
result = testdir.runpytest_subprocess()
155-
result.stdout.fnmatch_lines(
155+
result.stderr.fnmatch_lines(
156156
[
157157
"::error file=test_class_method.py,line=7::TestClass.test_method*assert 1 == 2*",
158158
]
@@ -178,7 +178,7 @@ def test_param(a, b):
178178
)
179179
testdir.monkeypatch.setenv("GITHUB_ACTIONS", "true")
180180
result = testdir.runpytest_subprocess()
181-
result.stdout.fnmatch_lines(
181+
result.stderr.fnmatch_lines(
182182
[
183183
"::error file=test_annotation_param.py,line=11::test_param?other?1*assert 2 == 3*",
184184
]

pytest_github_actions_annotate_failures/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import print_function
33

44
import os
5+
import sys
56
from collections import OrderedDict
67

78
import pytest
@@ -52,7 +53,9 @@ def pytest_runtest_makereport(item, call):
5253
except AttributeError:
5354
pass
5455

55-
print(_error_workflow_command(filesystempath, lineno, longrepr))
56+
print(
57+
_error_workflow_command(filesystempath, lineno, longrepr), file=sys.stderr
58+
)
5659

5760

5861
def _error_workflow_command(filesystempath, lineno, longrepr):

0 commit comments

Comments
 (0)