How to show detailed differences in py.test without a detailed test?

py.test --verbose is required to show the complete difference with statement errors, but it also displays the full name of each test at runtime (which is noisy).

I would like the full differences to show up when the statement fails, but I want only one . appeared when running tests. Is there any way to do this?

+10
source share
2 answers

Unfortunately, there are no configuration or command line flags for this, since this one is hardcoded deep inside pytest : when you define --verbose , you will get the whole package. However, I managed to come up with this hacker hack. Put the following function in 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 fix relying on pytest internals, not guaranteed compatibility with future versions, and ugly as a sin. You can also make this correction based on a different user configuration of the command line argument.

+3
source

Based on @bereal's answer

(this is good, but some Pytest changes should be followed)

 def pytest_configure(config): terminal = config.pluginmanager.getplugin('terminal') class QuietReporter(terminal.TerminalReporter): @property def verbosity(self): return 0 @property def showlongtestinfo(self): return False @property def showfspath(self): return False terminal.TerminalReporter = QuietReporter 
0
source

Source: https://habr.com/ru/post/989400/


All Articles