Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show verbose py.test diffs without verbose test progress?

Tags:

python

pytest

py.test's --verbose option is required to show full diffs on assertion failures, but this also displays the full name of each test during execution (which is noisy).

I'd like full diffs to show when an assertion fails, but I only want single .'s to appear when the tests are running. Is there a way to do this?

like image 680
Jace Browning Avatar asked Jun 19 '15 12:06

Jace Browning


People also ask

How do you make pytest more verbose?

Running pytest -vv should make your output more verbose. If you want your output to be less verbose, try pytest -q or pytest --quiet .

What is verbose in pytest?

Verbosity. The -v flag controls the verbosity of pytest output in various aspects: test session progress, assertion details when tests fail, fixtures details with --fixtures , etc.

What is Conftest py in pytest?

conftest.py is where you setup test configurations and store the testcases that are used by test functions. The configurations and the testcases are called fixture in pytest. The test_*. py files are where the actual test functions reside.


1 Answers

Unfortunately, there seems to be no configuration or command line flag for that, since that's hard-coded deep inside pytest: when you define --verbose, you get the whole package. However, I've managed to come up with this hackish hack. Put the following function into your conftest.py:

def pytest_configure(config):
    terminal = config.pluginmanager.getplugin('terminal')
    BaseReporter = terminal.TerminalReporter
    class QuietReporter(BaseReporter):
        def __init__(self, *args, **kwargs):
            BaseReporter.__init__(self, *args, **kwargs)
            self.verbosity = 0
            self.showlongtestinfo = self.showfspath = False

    terminal.TerminalReporter = QuietReporter 

This is essentially a monkey-patching, relying on pytest internals, not guaranteed to be compatible with the future versions and ugly as sin. You can also make this patch conditional based on some other custom configuration of command-line argument.

like image 60
bereal Avatar answered Sep 25 '22 03:09

bereal