mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-02-02 02:40:42 +01:00
Add test start time info to custom TerminalReporter. Put install_terminal into peporter class.
This commit is contained in:
parent
c84dc5f13e
commit
a527bd0a05
@ -54,6 +54,7 @@ from configparser import ConfigParser, ExtendedInterpolation
|
||||
from packaging.specifiers import SpecifierSet
|
||||
from packaging.version import parse
|
||||
import time
|
||||
from datetime import datetime
|
||||
from threading import Thread, Barrier, Event
|
||||
from firebird.driver import connect, connect_server, create_database, driver_config, \
|
||||
NetProtocol, Server, CHARSET_MAP, Connection, Cursor, \
|
||||
@ -199,10 +200,14 @@ def remove_dir(path: Path) -> None:
|
||||
path.rmdir()
|
||||
|
||||
class QATerminalReporter(TerminalReporter):
|
||||
"""Custom `TerminalReporter` that prints our QA test IDs instead pytest node IDs.
|
||||
"""Custom `TerminalReporter` that prints tests start time.
|
||||
Also it prints our QA test IDs instead pytest node IDs if 'instal_terminals' option is specified.
|
||||
|
||||
The code was directly taken from pytest source and adapted to our needs.
|
||||
"""
|
||||
def __init__(self, config, install_terminals):
|
||||
super(QATerminalReporter, self).__init__(config)
|
||||
self.install_terminals = install_terminals
|
||||
def _getfailureheadline(self, rep):
|
||||
head_line = rep.head_line
|
||||
if head_line:
|
||||
@ -211,7 +216,7 @@ class QATerminalReporter(TerminalReporter):
|
||||
def pytest_runtest_logstart(self, nodeid: str, location: Tuple[str, Optional[int], str]) -> None:
|
||||
# Ensure that the path is printed before the
|
||||
# 1st test of a module starts running.
|
||||
nodeid = _nodemap.get(nodeid, nodeid)
|
||||
nodeid = _nodemap.get(nodeid, nodeid) if self.install_terminals else nodeid
|
||||
if self.showlongtestinfo:
|
||||
line = nodeid + ' '
|
||||
self.write_ensure_prefix(line, "")
|
||||
@ -250,7 +255,7 @@ class QATerminalReporter(TerminalReporter):
|
||||
self._tw.write(letter, **markup)
|
||||
else:
|
||||
self._progress_nodeids_reported.add(rep.nodeid)
|
||||
line = rep._qa_id_ + ' '
|
||||
line = (rep._qa_id_ + ' ') if self.install_terminals else self._locationline(rep.nodeid, *rep.location)
|
||||
if not running_xdist:
|
||||
self.write_ensure_prefix(line, word, **markup)
|
||||
|
||||
@ -286,6 +291,16 @@ class QATerminalReporter(TerminalReporter):
|
||||
self.currentfspath = -2
|
||||
self.flush()
|
||||
|
||||
def write_ensure_prefix(self, prefix: str, extra: str = "", **kwargs) -> None:
|
||||
start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
if self.currentfspath != prefix:
|
||||
self._tw.line()
|
||||
self.currentfspath = prefix
|
||||
self._tw.write(f"{start_time} {prefix}")
|
||||
if extra:
|
||||
self._tw.write(extra, **kwargs)
|
||||
self.currentfspath = -2
|
||||
|
||||
@pytest.mark.tryfirst
|
||||
def pytest_runtest_makereport(item, call):
|
||||
"""Our replacement for pytest hook that is called to create a `TestReport` for each of
|
||||
@ -431,11 +446,10 @@ def pytest_configure(config):
|
||||
if platform.system != 'Windows':
|
||||
samle_qa.chmod(16895)
|
||||
# Change terminal reporter
|
||||
if config.getoption('install_terminal'):
|
||||
standard_reporter = config.pluginmanager.getplugin('terminalreporter')
|
||||
pspec_reporter = QATerminalReporter(standard_reporter.config)
|
||||
config.pluginmanager.unregister(standard_reporter)
|
||||
config.pluginmanager.register(pspec_reporter, 'terminalreporter')
|
||||
standard_reporter = config.pluginmanager.getplugin('terminalreporter')
|
||||
pspec_reporter = QATerminalReporter(standard_reporter.config, config.getoption('install_terminal'))
|
||||
config.pluginmanager.unregister(standard_reporter)
|
||||
config.pluginmanager.register(pspec_reporter, 'terminalreporter')
|
||||
|
||||
def pytest_collection_modifyitems(session, config, items):
|
||||
"""Post-processing of collected tests. deselects or mark for skip tests that are not
|
||||
|
Loading…
Reference in New Issue
Block a user