Opened 4 years ago
Last modified 3 years ago
#32939 assigned Cleanup/optimization
Change override_settings to do its subclass check lazily — at Version 2
| Reported by: | Chris Jerdonek | Owned by: | nobody |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Florian Demmer | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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. This AuthViewsTestCase change could be done in a nicer way once this ticket is implemented, perhaps even as part of this ticket.
Change History (2)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
| Description: | modified (diff) |
|---|
PS - should this be a
TypeErrorinstead ofValueError?