From ee327dc87d123dbc4210c4780a4e9940a915b522 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 18 Sep 2019 10:12:17 +0200 Subject: [PATCH] remove an ancient hack on context-teardown, refine and use more regular API for finalizing online accounts --- python/src/deltachat/account.py | 8 ++++---- python/src/deltachat/chatting.py | 1 - python/tests/conftest.py | 15 +++------------ 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index bba09f31b..0cba54521 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -50,9 +50,8 @@ class Account(object): self._configkeys = self.get_config("sys.config_keys").split() self._imex_completed = threading.Event() - # XXX this can cause "illegal instructions" at test ends so we omit it for now - # def __del__(self): - # self.shutdown() + def __del__(self): + self.shutdown() def _check_config_key(self, name): if name not in self._configkeys: @@ -397,7 +396,8 @@ class Account(object): def shutdown(self, wait=True): """ stop threads and close and remove underlying dc_context and callbacks. """ if hasattr(self, "_dc_context") and hasattr(self, "_threads"): - self.stop_threads(wait=False) # to interrupt idle and tell python threads to stop + print("SHUTDOWN", self) + self.stop_threads(wait=False) lib.dc_close(self._dc_context) self.stop_threads(wait=wait) # to wait for threads deltachat.clear_context_callback(self._dc_context) diff --git a/python/src/deltachat/chatting.py b/python/src/deltachat/chatting.py index 0f0bbd11f..56e095194 100644 --- a/python/src/deltachat/chatting.py +++ b/python/src/deltachat/chatting.py @@ -305,7 +305,6 @@ class Chat(object): def get_contacts(self): """ get all contacts for this chat. :params: contact object. - :raises ValueError: if contact could not be added :returns: list of :class:`deltachat.chatting.Contact` objects for this chat """ diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 1e8e6dece..d1a023247 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -24,17 +24,6 @@ def pytest_configure(config): config.option.liveconfig = cfg -@pytest.hookimpl(trylast=True) -def pytest_runtest_call(item): - # perform early finalization because we otherwise get cloberred - # output from concurrent threads printing between execution - # of the test function and the teardown phase of that test function - if "acfactory" in item.funcargs: - print("*"*30, "finalizing", "*"*30) - acfactory = item.funcargs["acfactory"] - acfactory.finalize() - - def pytest_report_header(config, startdir): summary = [] @@ -184,7 +173,9 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig): self._finalizers.append(ac.shutdown) return ac - return AccountMaker() + am = AccountMaker() + request.addfinalizer(am.finalize) + return am @pytest.fixture