From c79472a4c61d5af142d5e69f34e9f624a42dd29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Thu, 11 Jul 2024 15:38:11 +0200 Subject: [PATCH] mongoengine: Prefer addClassCleanup over tearDownClass > If setUpClass() fails, meaning that tearDownClass() is not called, then any cleanup functions added will still be called. --- tests/test_mongoengine.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py index aeeb80fa..b39c6b3f 100644 --- a/tests/test_mongoengine.py +++ b/tests/test_mongoengine.py @@ -59,12 +59,12 @@ def setUpClass(cls, **kwargs): **kwargs, ) - @classmethod - def tearDownClass(cls): - cls.db.drop_database(cls.db_name) - mongoengine.connection.disconnect() - PersonFactory.reset_sequence() - AddressFactory.reset_sequence() + def cleanup(): + cls.db.drop_database(cls.db_name) + mongoengine.connection.disconnect() + PersonFactory.reset_sequence() + AddressFactory.reset_sequence() + cls.addClassCleanup(cleanup) def test_build(self): std = PersonFactory.build()