Commit fe369d32 authored by Kirill Smelkov's avatar Kirill Smelkov

tests: Reset transaction synchronizers before every test run

Else, e.g. after a failing test, that closed its storage and DB, but not
all Connections, another test, just by starting new transaction, would
invoke synchronization on that unclosed connection, which will try to
access closed storage and likely fail.

Fixes e.g.

Crash scenariou is the same as described in 5a5ed2c7 (tests: Force-close
ZODB connections in teardown, that testing code forgot to explicitly
close). Only now we try to isolate tests from each other not only for
different modules, but also for tests inside the same module.
parent c37a989d
# Wendelin.core | pytest config
# Copyright (C) 2020-2021 Nexedi SA and Contributors.
# Kirill Smelkov <>
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# See COPYING file for full licensing terms.
# See for rationale and options.
from __future__ import print_function, absolute_import
import pytest
import transaction
# 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.
def transaction_reset():
# nothing to run after test
# Wendelin. Testing utilities
# Copyright (C) 2014-2020 Nexedi SA and Contributors.
# Copyright (C) 2014-2021 Nexedi SA and Contributors.
# Kirill Smelkov <>
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -204,6 +204,10 @@ class TestDB_Base(object):
def teardown(self):
# 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:
conn = connref()
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