Skip to content

Commit

Permalink
mongoengine: Prefer addClassCleanup over tearDownClass
Browse files Browse the repository at this point in the history
> If setUpClass() fails, meaning that tearDownClass() is not called,
  then any cleanup functions added will still be called.
  • Loading branch information
francoisfreitag committed Jul 11, 2024
1 parent da6ce0e commit 96598dd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/test_mongoengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 96598dd

Please sign in to comment.