override_settings doesn't work with unittest.TestCase subclasses
|Reported by:||Claude Paroz||Owned by:||nobody|
|Cc:||asendecka@…||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, if you decorate with override_settings a subclass of unittest.TestCase, all tests in the class are silently skipped. This is happening because of the issubclass(TransactionTestCase) test here: https://github.com/django/django/blob/master/django/test/utils.py#L188
We cannot simply change the issubclass test, because ut.TestCase doesn't have any _pre_setup mechanism.
I can see two ways forward:
- Document that override_settings cannot decorate unittest.TestClass subclasses, and raise an error when the decorator is applied to anything other than TransactionTestCase subclasses.
- Instead of using _pre_setup, use setUpClass to enable the overriden settings.
I'd really like to see the second alternative implemented. However, this means that the override_settings machinery will only run at the start of the TestClass tests, and no more between each test (unless the specific test itself is decorated by override_settings). This shouldn't disturb the test system more than that.
Change History (11)
comment:2 follow-up: 3 Changed 4 years ago by
|Triage Stage:||Ready for checkin → Design decision needed|