Skip to content

Commit

Permalink
Add tests for progress output and docs for console_output_style
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Nov 21, 2017
1 parent 3441084 commit 3a5dbab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
7 changes: 5 additions & 2 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down Expand Up @@ -300,7 +300,10 @@ def pytest_runtest_logreport(self, report):
else:
self.ensure_newline()
self.writer.write("[%s]" % rep.node.gateway.id)
self.writer.write(self._get_progress_information_message() + " ", cyan=True)
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
Expand Down
19 changes: 19 additions & 0 deletions doc/en/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 55 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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\]',
])

0 comments on commit 3a5dbab

Please sign in to comment.