I have been struggling with this issue with my tests and I think it boils down to a confusion of levels between what an app and project is, and if so it may be something to improve in the django architecture. So here is the issue, which I think many will have experienced:
An app can be reusable and included in different projects. An app has its own tests. These tests are self contained and usually load data in the form of fixtures. Even though tests are self contained, they are always run in the context of a django project with its own settings and other apps installed. Issues arise when using signals from one app to the other. Then whatever app1 test is doing, it may trigger a signal receiver in app2, for which the test may not have initialized any data, making the test to break. Its not that there is a problem with app2, only that its data has not been setup. Since app1 should not know about app2, it doesnt load any fixture for app2’s data.
Tests and apps should be self contained but tests are run in the context of a project with many apps, this is the confusion of levels that I’m speaking of. AFAIK I could create different
AppConfigs where signals are connected or not, but I don’t know how to use different
AppConfigs when testing different apps. It makes sense that the app that connects receivers to another app knows that it should detach these receivers when running a test for that other app.
Maybe the answer is just: “not run tests for app1 in that project, rather run them in another project separately”. But maybe there is a better way?