mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 13:33:07 +01:00
Added "start-time" option to print tests start time info. Don't print by default.
Redefine write_fspath_result method to print info without verbose mode too.
This commit is contained in:
parent
2065fee8b9
commit
3197004013
@ -48,6 +48,7 @@ import weakref
|
|||||||
import pytest
|
import pytest
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
from configparser import ConfigParser, ExtendedInterpolation
|
||||||
from _pytest.terminal import TerminalReporter, _get_raw_skip_reason, _format_trimmed
|
from _pytest.terminal import TerminalReporter, _get_raw_skip_reason, _format_trimmed
|
||||||
|
from _pytest.pathlib import bestrelpath
|
||||||
from subprocess import run, CompletedProcess, PIPE, STDOUT
|
from subprocess import run, CompletedProcess, PIPE, STDOUT
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
from configparser import ConfigParser, ExtendedInterpolation
|
||||||
@ -164,6 +165,7 @@ def pytest_addoption(parser, pluginmanager):
|
|||||||
help="SKIP tests instead deselection")
|
help="SKIP tests instead deselection")
|
||||||
grp.addoption('--extend-xml', action='store_true', default=False, help="Extend XML JUnit report with additional information")
|
grp.addoption('--extend-xml', action='store_true', default=False, help="Extend XML JUnit report with additional information")
|
||||||
grp.addoption('--install-terminal', action='store_true', default=False, help="Use our own terminal reporter")
|
grp.addoption('--install-terminal', action='store_true', default=False, help="Use our own terminal reporter")
|
||||||
|
grp.addoption('--start-time', action='store_true', dest="start_time_info", default=False, help="Show tests start time info")
|
||||||
|
|
||||||
def pytest_report_header(config):
|
def pytest_report_header(config):
|
||||||
"""Returns plugin-specific test session header.
|
"""Returns plugin-specific test session header.
|
||||||
@ -200,14 +202,16 @@ def remove_dir(path: Path) -> None:
|
|||||||
path.rmdir()
|
path.rmdir()
|
||||||
|
|
||||||
class QATerminalReporter(TerminalReporter):
|
class QATerminalReporter(TerminalReporter):
|
||||||
"""Custom `TerminalReporter` that prints tests start time.
|
"""Custom `TerminalReporter`
|
||||||
Also it prints our QA test IDs instead pytest node IDs if 'instal_terminals' option is specified.
|
Prints tests start time if '--start-time' option is specified.
|
||||||
|
Prints our QA test IDs instead pytest node IDs if '--install-terminal' option is specified.
|
||||||
|
|
||||||
The code was directly taken from pytest source and adapted to our needs.
|
The code was directly taken from pytest source and adapted to our needs.
|
||||||
"""
|
"""
|
||||||
def __init__(self, config, install_terminals):
|
def __init__(self, config, install_terminals, start_time_info):
|
||||||
super(QATerminalReporter, self).__init__(config)
|
super(QATerminalReporter, self).__init__(config)
|
||||||
self.install_terminals = install_terminals
|
self.install_terminals = install_terminals
|
||||||
|
self.start_time_info = start_time_info
|
||||||
def _getfailureheadline(self, rep):
|
def _getfailureheadline(self, rep):
|
||||||
head_line = rep.head_line
|
head_line = rep.head_line
|
||||||
if head_line:
|
if head_line:
|
||||||
@ -292,15 +296,27 @@ class QATerminalReporter(TerminalReporter):
|
|||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def write_ensure_prefix(self, prefix: str, extra: str = "", **kwargs) -> None:
|
def write_ensure_prefix(self, prefix: str, extra: str = "", **kwargs) -> None:
|
||||||
start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
start_time = (datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] + ' ') if self.start_time_info else ''
|
||||||
if self.currentfspath != prefix:
|
if self.currentfspath != prefix:
|
||||||
self._tw.line()
|
self._tw.line()
|
||||||
self.currentfspath = prefix
|
self.currentfspath = prefix
|
||||||
self._tw.write(f"{start_time} {prefix}")
|
self._tw.write(f"{start_time}{prefix}")
|
||||||
if extra:
|
if extra:
|
||||||
self._tw.write(extra, **kwargs)
|
self._tw.write(extra, **kwargs)
|
||||||
self.currentfspath = -2
|
self.currentfspath = -2
|
||||||
|
|
||||||
|
def write_fspath_result(self, nodeid: str, res, **markup: bool) -> None:
|
||||||
|
start_time = (datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] + ' ') if self.start_time_info else ''
|
||||||
|
fspath = self.config.rootpath / nodeid.split("::")[0]
|
||||||
|
if self.currentfspath is None or fspath != self.currentfspath:
|
||||||
|
if self.currentfspath is not None and self._show_progress_info:
|
||||||
|
self._write_progress_information_filling_space()
|
||||||
|
self.currentfspath = fspath
|
||||||
|
relfspath = bestrelpath(self.startpath, fspath)
|
||||||
|
self._tw.line()
|
||||||
|
self._tw.write(start_time + relfspath + " ")
|
||||||
|
self._tw.write(res, flush=True, **markup)
|
||||||
|
|
||||||
@pytest.mark.tryfirst
|
@pytest.mark.tryfirst
|
||||||
def pytest_runtest_makereport(item, call):
|
def pytest_runtest_makereport(item, call):
|
||||||
"""Our replacement for pytest hook that is called to create a `TestReport` for each of
|
"""Our replacement for pytest hook that is called to create a `TestReport` for each of
|
||||||
@ -447,7 +463,7 @@ def pytest_configure(config):
|
|||||||
samle_qa.chmod(16895)
|
samle_qa.chmod(16895)
|
||||||
# Change terminal reporter
|
# Change terminal reporter
|
||||||
standard_reporter = config.pluginmanager.getplugin('terminalreporter')
|
standard_reporter = config.pluginmanager.getplugin('terminalreporter')
|
||||||
pspec_reporter = QATerminalReporter(standard_reporter.config, config.getoption('install_terminal'))
|
pspec_reporter = QATerminalReporter(standard_reporter.config, config.getoption('install_terminal'), config.getoption('start_time_info'))
|
||||||
config.pluginmanager.unregister(standard_reporter)
|
config.pluginmanager.unregister(standard_reporter)
|
||||||
config.pluginmanager.register(pspec_reporter, 'terminalreporter')
|
config.pluginmanager.register(pspec_reporter, 'terminalreporter')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user