Opened 4 years ago
Last modified 2 years ago
#32939 assigned Cleanup/optimization
Change override_settings to do its subclass check lazily — at Initial Version
Description ¶
Currently, the @override_settings
decorator raises a ValueError
if it's used to decorate a class that doesn't inherit from SimpleTestCase
:
https://github.com/django/django/blob/56f9579105c324ff15250423bf9f8bdf1634cfb4/django/test/utils.py#L519-L521
However, this prevents the decorator from being useable as a test-class mixin for a number of SimpleTestCase
subclasses. When creating shared test-class functionality, it's often better to use a mixin rather than a concrete TestCase
class. This way the mixin won't have its setUp
methods run unnecessarily on a test-case class with no tests, and it won't count towards the parallel test runner's test-case class count, etc.
The check could instead be done lazily, e.g. inside setUpClass()
, while still having the same desired effect.
I noticed this when seeing if I could convert AuthViewsTestCase
into a mixin:
https://github.com/django/django/blob/56f9579105c324ff15250423bf9f8bdf1634cfb4/tests/auth_tests/test_views.py
The AuthViewsTestCase
change could be done in a nicer way once this ticket is implemented, perhaps even as part of this ticket.
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.