Opened 3 years ago
Closed 3 years ago
#33278 closed Cleanup/optimization (fixed)
Use a custom exception type with django.test.testcases._DatabaseFailure
Reported by: | Daniel Hahler | Owned by: | SwastikTripathi |
---|---|---|---|
Component: | Testing framework | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Simon Charette | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently an AssertionError
with a message is used in case of blocked DB operations:
class _DatabaseFailure: def __init__(self, wrapped, message): self.wrapped = wrapped self.message = message def __call__(self): raise AssertionError(self.message)
(source)
Using a custom/distinctive exception type would allow for better catching and handling of this.
Currently you would have to parse its message
and/or look at the stack trace to see if it's this specific error, or a "normal" assertion error from a test.
Change History (6)
comment:1 by , 3 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 years ago
Sounds reasonable to me as well, I assume we'll want to subclass AssertionError
but a distinct type shouldn't hurt.
comment:3 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Yes we can surely do that. Here's my PR https://github.com/django/django/pull/15082
comment:4 by , 3 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:5 by , 3 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Sounds reasonable, thanks.