Skip to content

Commit 6991a16

Browse files
committed
Fix bad console output when using console_output_style=classic
Fix #3883
1 parent a319674 commit 6991a16

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

changelog/3883.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bad console output when using ``console_output_style=classic``.

src/_pytest/terminal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def hasopt(self, char):
263263
def write_fspath_result(self, nodeid, res):
264264
fspath = self.config.rootdir.join(nodeid.split("::")[0])
265265
if fspath != self.currentfspath:
266-
if self.currentfspath is not None:
266+
if self.currentfspath is not None and self._show_progress_info:
267267
self._write_progress_information_filling_space()
268268
self.currentfspath = fspath
269269
fspath = self.startdir.bestrelpath(fspath)
@@ -358,12 +358,12 @@ def pytest_runtest_logstart(self, nodeid, location):
358358
def pytest_runtest_logreport(self, report):
359359
rep = report
360360
res = self.config.hook.pytest_report_teststatus(report=rep)
361-
cat, letter, word = res
361+
category, letter, word = res
362362
if isinstance(word, tuple):
363363
word, markup = word
364364
else:
365365
markup = None
366-
self.stats.setdefault(cat, []).append(rep)
366+
self.stats.setdefault(category, []).append(rep)
367367
self._tests_ran = True
368368
if not letter and not word:
369369
# probably passed setup/teardown

testing/test_terminal.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from __future__ import absolute_import, division, print_function
55
import collections
6+
import os
67
import sys
78
import textwrap
89

@@ -472,7 +473,7 @@ def test_three():
472473

473474
def test_show_deselected_items_using_markexpr_before_test_execution(self, testdir):
474475
testdir.makepyfile(
475-
"""
476+
test_show_deselected="""
476477
import pytest
477478
478479
@pytest.mark.foo
@@ -491,7 +492,7 @@ def test_pass():
491492
result.stdout.fnmatch_lines(
492493
[
493494
"collected 3 items / 1 deselected",
494-
"*test_show_des*.py ..*",
495+
"*test_show_deselected.py ..*",
495496
"*= 2 passed, 1 deselected in * =*",
496497
]
497498
)
@@ -1134,7 +1135,53 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
11341135
assert "inifile: tox.ini\n" in result.stdout.str()
11351136

11361137

1137-
class TestProgress(object):
1138+
class TestClassicOutputStyle(object):
1139+
"""Ensure classic output style works as expected (#3883)"""
1140+
1141+
@pytest.fixture
1142+
def test_files(self, testdir):
1143+
testdir.makepyfile(
1144+
**{
1145+
"test_one.py": "def test_one(): pass",
1146+
"test_two.py": "def test_two(): assert 0",
1147+
"sub/test_three.py": """
1148+
def test_three_1(): pass
1149+
def test_three_2(): assert 0
1150+
def test_three_3(): pass
1151+
""",
1152+
}
1153+
)
1154+
1155+
def test_normal_verbosity(self, testdir, test_files):
1156+
result = testdir.runpytest("-o", "console_output_style=classic")
1157+
result.stdout.fnmatch_lines(
1158+
[
1159+
"test_one.py .",
1160+
"test_two.py F",
1161+
"sub{}test_three.py .F.".format(os.sep),
1162+
"*2 failed, 3 passed in*",
1163+
]
1164+
)
1165+
1166+
def test_verbose(self, testdir, test_files):
1167+
result = testdir.runpytest("-o", "console_output_style=classic", "-v")
1168+
result.stdout.fnmatch_lines(
1169+
[
1170+
"test_one.py::test_one PASSED",
1171+
"test_two.py::test_two FAILED",
1172+
"sub{}test_three.py::test_three_1 PASSED".format(os.sep),
1173+
"sub{}test_three.py::test_three_2 FAILED".format(os.sep),
1174+
"sub{}test_three.py::test_three_3 PASSED".format(os.sep),
1175+
"*2 failed, 3 passed in*",
1176+
]
1177+
)
1178+
1179+
def test_quiet(self, testdir, test_files):
1180+
result = testdir.runpytest("-o", "console_output_style=classic", "-q")
1181+
result.stdout.fnmatch_lines([".F.F.", "*2 failed, 3 passed in*"])
1182+
1183+
1184+
class TestProgressOutputStyle(object):
11381185
@pytest.fixture
11391186
def many_tests_files(self, testdir):
11401187
testdir.makepyfile(

0 commit comments

Comments
 (0)