Add tests for progress output and docs for ``console_output_style``

Fix #2657
This commit is contained in:
Bruno Oliveira 2017-11-21 20:43:12 -02:00
parent 3441084bd2
commit 3a5dbabf60
3 changed files with 79 additions and 2 deletions

View File

@ -52,7 +52,7 @@ def pytest_addoption(parser):
help="color terminal output (yes/no/auto).")
parser.addini("console_output_style",
help="console output: classic or with additional progress information.",
help="console output: classic or with additional progress information (classic|progress).",
default='progress')
@ -300,7 +300,10 @@ class TerminalReporter:
else:
self.ensure_newline()
self.writer.write("[%s]" % rep.node.gateway.id)
if self._show_progress_info:
self.writer.write(self._get_progress_information_message() + " ", cyan=True)
else:
self.writer.write(' ')
self.writer.write(word, **markup)
self.writer.write(" " + line)
self.currentfspath = -2

View File

@ -312,3 +312,22 @@ Builtin configuration file options
relative to :ref:`rootdir <rootdir>`. Additionally path may contain environment
variables, that will be expanded. For more information about cache plugin
please refer to :ref:`cache_provider`.
.. confval:: console_output_style
.. versionadded:: 3.3
Sets the console output style while running tests:
* ``classic``: classic pytest output.
* ``progress``: like classic pytest output, but with a progress indicator.
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
the new mode is causing unexpected problems:
.. code-block:: ini
# content of pytest.ini
[pytest]
console_output_style = classic

View File

@ -964,3 +964,58 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
testdir.makeini('[pytest]')
result = testdir.runpytest('')
assert 'inifile: tox.ini\n' in result.stdout.str()
class TestProgress:
@pytest.fixture
def many_tests_file(self, testdir):
testdir.makepyfile(
test_bar="""
import pytest
@pytest.mark.parametrize('i', range(10))
def test_bar(i): pass
""",
test_foo="""
import pytest
@pytest.mark.parametrize('i', range(5))
def test_foo(i): pass
""",
test_foobar="""
import pytest
@pytest.mark.parametrize('i', range(5))
def test_foobar(i): pass
""",
)
def test_normal(self, many_tests_file, testdir):
output = testdir.runpytest()
output.stdout.re_match_lines([
r'test_bar.py \.\.\.\.\.\.\.\.\.\. \s+ \[ 50%\]',
r'test_foo.py \.\.\.\.\. \s+ \[ 75%\]',
r'test_foobar.py \.\.\.\.\. \s+ \[100%\]',
])
def test_verbose(self, many_tests_file, testdir):
output = testdir.runpytest('-v')
output.stdout.re_match_lines([
r'test_bar.py::test_bar\[0\] PASSED \s+ \[ 5%\]',
r'test_foo.py::test_foo\[4\] PASSED \s+ \[ 75%\]',
r'test_foobar.py::test_foobar\[4\] PASSED \s+ \[100%\]',
])
def test_xdist_normal(self, many_tests_file, testdir):
pytest.importorskip('xdist')
output = testdir.runpytest('-n2')
output.stdout.re_match_lines([
r'\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\. \s+ \[100%\]',
])
def test_xdist_verbose(self, many_tests_file, testdir):
pytest.importorskip('xdist')
output = testdir.runpytest('-n2', '-v')
output.stdout.re_match_lines_random([
r'\[gw\d\] \[\s*\d+%\] PASSED test_bar.py::test_bar\[1\]',
r'\[gw\d\] \[\s*\d+%\] PASSED test_foo.py::test_foo\[1\]',
r'\[gw\d\] \[\s*\d+%\] PASSED test_foobar.py::test_foobar\[1\]',
])