[Answered ]-Cleaning up after a unit test that asserts an IntegrityError is thrown

2👍

You should not need to worry about the cleanup. pytest-django’s db fixture disables transactions for the test, executing the entire test in one transaction and rolling back the transaction at the end. This ensures the database remains clean.

If the test requires transaction there’s the transactional_db fixture which will enable transactions (slower) and flush the entire contents of the db after the test (very slow) again cleaning up for you.

So if the cleanup does not happen then you should probably file a bug at pytest-django. But I would be surprised if this is the case unless I missed something important.

👤flub

Leave a comment