Commit 96df97a0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e2dc8651
...@@ -20,10 +20,32 @@ ...@@ -20,10 +20,32 @@
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
import pytest
import transaction
from golang import func, defer from golang import func, defer
from functools import partial from functools import partial
import gc import gc
# reset transaction synchronizers before every test run.
#
# This isolates different tests from each other. When there is failure in test A,
# and it is not careful enough to close all ZODB Connections (but DB and
# storage are closed), those connections will continue to participate in
# transaction boundaries, and crash on access to closed storage.
#
# Fix it once and for all in one place here.
# It would be more easy if DB.close would call conn.close for all its opened
# connections, but unfortunately it is not the case.
#
# See also TestDB_Base.teardown, but it isolates only module Ma from module Mb,
# not test M.A from test M.B.
@pytest.fixture(autouse=True)
def transaction_reset():
transaction.manager.clearSynchs()
yield
# nothing to run after test
# Before pytest exits, teardown WCFS(s) that we automatically spawned during # Before pytest exits, teardown WCFS(s) that we automatically spawned during
# test runs in bigfile/bigarray/... # test runs in bigfile/bigarray/...
# #
......
# Wendelin. Testing utilities # Wendelin. Testing utilities
# Copyright (C) 2014-2020 Nexedi SA and Contributors. # Copyright (C) 2014-2021 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -204,6 +204,10 @@ class TestDB_Base(object): ...@@ -204,6 +204,10 @@ class TestDB_Base(object):
def teardown(self): def teardown(self):
# close connections that test code forgot to close # close connections that test code forgot to close
#
# see also conftest.transaction_reset(), which tries to isolate all
# tests from each other. (TestDB_Base.teardown - on the other hand - is
# invoked per module and so isolates at module-level only)
for connref, tb in self.connv: for connref, tb in self.connv:
conn = connref() conn = connref()
if conn is None: if conn is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment