add --extra-info CLI option (defaults to False for interactive runs)

This commit is contained in:
holger krekel
2022-05-02 13:44:17 +02:00
parent b373e7acba
commit 026dd4480e
3 changed files with 33 additions and 25 deletions

View File

@@ -250,7 +250,7 @@ class EventThread(threading.Thread):
hook = getattr(self.account._pm.hook, name) hook = getattr(self.account._pm.hook, name)
hook(**kwargs) hook(**kwargs)
except Exception: except Exception:
if self.account._dc_context is not None: if not self._marked_for_shutdown and self.account._dc_context is not None:
raise raise
def _map_ffi_event(self, ffi_event: FFIEvent): def _map_ffi_event(self, ffi_event: FFIEvent):

View File

@@ -22,19 +22,24 @@ import deltachat
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption( group = parser.getgroup("deltachat testplugin options")
group.addoption(
"--liveconfig", action="store", default=None, "--liveconfig", action="store", default=None,
help="a file with >=2 lines where each line " help="a file with >=2 lines where each line "
"contains NAME=VALUE config settings for one account" "contains NAME=VALUE config settings for one account"
) )
parser.addoption( group.addoption(
"--ignored", action="store_true", "--ignored", action="store_true",
help="Also run tests marked with the ignored marker", help="Also run tests marked with the ignored marker",
) )
parser.addoption( group.addoption(
"--strict-tls", action="store_true", "--strict-tls", action="store_true",
help="Never accept invalid TLS certificates for test accounts", help="Never accept invalid TLS certificates for test accounts",
) )
group.addoption(
"--extra-info", action="store_true",
help="show more info on failures (imap server state, config)"
)
def pytest_configure(config): def pytest_configure(config):
@@ -89,9 +94,12 @@ def pytest_configure(config):
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item): def pytest_runtest_teardown(self, item):
self.enable_logging(item) logging = item.config.getoption("--extra-info")
if logging:
self.enable_logging(item)
yield yield
self.disable_logging(item) if logging:
self.disable_logging(item)
la = LoggingAspect() la = LoggingAspect()
config.pluginmanager.register(la) config.pluginmanager.register(la)
@@ -126,12 +134,12 @@ def pytest_report_header(config, startdir):
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def testprocess(request): def testprocess(request):
return TestProcess(request.config.option.liveconfig) return TestProcess(pytestconfig=request.config)
class TestProcess: class TestProcess:
def __init__(self, liveconfig_opt): def __init__(self, pytestconfig):
self.liveconfig_opt = liveconfig_opt self.pytestconfig = pytestconfig
def get_liveconfig_producer(self): def get_liveconfig_producer(self):
""" provide live account configs, cached on a per-test-process scope """ provide live account configs, cached on a per-test-process scope
@@ -139,7 +147,7 @@ class TestProcess:
Depending on the --liveconfig option this comes from Depending on the --liveconfig option this comes from
a HTTP provider or a file with a line specifying each accounts config. a HTTP provider or a file with a line specifying each accounts config.
""" """
liveconfig_opt = self.liveconfig_opt liveconfig_opt = self.pytestconfig.getoption("--liveconfig")
if not liveconfig_opt: if not liveconfig_opt:
pytest.skip("specify DCC_NEW_TMP_EMAIL or --liveconfig to provide live accounts") pytest.skip("specify DCC_NEW_TMP_EMAIL or --liveconfig to provide live accounts")
@@ -206,19 +214,20 @@ class ACFactory:
_finalizers: List[Callable[[], None]] _finalizers: List[Callable[[], None]]
_accounts: List[Account] _accounts: List[Account]
def __init__(self, strict_tls, tmpdir, testprocess, data) -> None: def __init__(self, request, testprocess, tmpdir, data) -> None:
self.strict_tls = strict_tls self.init_time = time.time()
self.tmpdir = tmpdir self.tmpdir = tmpdir
self._liveconfig_producer = testprocess.get_liveconfig_producer() self.pytestconfig = request.config
self.data = data
self.testprocess = testprocess self.testprocess = testprocess
self.data = data
self._liveconfig_producer = testprocess.get_liveconfig_producer()
self._finalizers = [] self._finalizers = []
self._accounts = [] self._accounts = []
self.init_time = time.time()
self._preconfigured_keys = ["alice", "bob", "charlie", self._preconfigured_keys = ["alice", "bob", "charlie",
"dom", "elena", "fiona"] "dom", "elena", "fiona"]
self.set_logging_default(False) self.set_logging_default(False)
request.addfinalizer(self.finalize)
def finalize(self): def finalize(self):
while self._finalizers: while self._finalizers:
@@ -242,7 +251,7 @@ class ACFactory:
if "e2ee_enabled" not in configdict: if "e2ee_enabled" not in configdict:
configdict["e2ee_enabled"] = "1" configdict["e2ee_enabled"] = "1"
if self.strict_tls: if self.testprocess.pytestconfig.getoption("--strict-tls"):
# Enable strict certificate checks for online accounts # Enable strict certificate checks for online accounts
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT) configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT) configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
@@ -428,16 +437,15 @@ class ACFactory:
@pytest.fixture @pytest.fixture
def acfactory(pytestconfig, tmpdir, request, testprocess, data): def acfactory(request, tmpdir, testprocess, data):
strict_tls = pytestconfig.getoption("--strict-tls") am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testprocess, data=data)
am = ACFactory(strict_tls, tmpdir, testprocess, data)
request.addfinalizer(am.finalize)
yield am yield am
if hasattr(request.node, "rep_call") and request.node.rep_call.failed: if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
logfile = io.StringIO() if testprocess.pytestconfig.getoption("--extra-info"):
am.dump_imap_summary(logfile=logfile) logfile = io.StringIO()
print(logfile.getvalue()) am.dump_imap_summary(logfile=logfile)
# request.node.add_report_section("call", "imap-server-state", s) print(logfile.getvalue())
# request.node.add_report_section("call", "imap-server-state", s)
class BotProcess: class BotProcess:

View File

@@ -8,7 +8,7 @@ envlist =
[testenv] [testenv]
commands = commands =
pytest -n1 --reruns 2 --reruns-delay 5 -v -rsXx --ignored --strict-tls {posargs: tests examples} pytest -n6 --extra-info --reruns 2 --reruns-delay 5 -v -rsXx --ignored --strict-tls {posargs: tests examples}
python tests/package_wheels.py {toxworkdir}/wheelhouse python tests/package_wheels.py {toxworkdir}/wheelhouse
passenv = passenv =
TRAVIS TRAVIS