TIL

Avoid database inconsistencies forcing pytest to use DB transactions

pytest-django's docs explain that you can use the same behavior from Django's TransactionTestCase with @pytest.mark.django_db(transaction=True). It will make test much slower, but can avoid errors in some cases.

Testing a post_delete signal that was supposed to delete a file from storage after a model instance was deleted, the storage's delete method was never called. Looking at the signal's implemetation, it turns out the deletion happened on commit. The code worked live, but not on tests because the tests never committed the transactions.