#30927 closed Cleanup/optimization (fixed)
Use assertWarnsMessage() in the example of deprecation warnings.
| Reported by: | André Ericson | Owned by: | André Ericson |
|---|---|---|---|
| Component: | Documentation | Version: | 2.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When adding deprecation warnings it's very likely that the documentation (https://docs.djangoproject.com/en/2.2/internals/contributing/writing-code/submitting-patches/#deprecating-a-feature) will be followed and the example of the test for the assertion will be copied.
import warnings
def test_foo_deprecation_warning(self):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always') # prevent warnings from appearing as errors
# invoke deprecated behavior
self.assertEqual(len(warns), 1)
msg = str(warns[0].message)
self.assertEqual(msg, 'Expected deprecation message')
This could be simplified as suggested here: https://github.com/django/django/pull/11905#discussion_r334984986
My suggestion is that we change the documentation to avoid unnecessary extra work.
Change History (7)
comment:1 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 6 years ago
| Summary: | Simplify example of test of deprecation warning. → Simplify the example for the test of deprecation warnings. |
|---|
comment:3 by , 6 years ago
| Summary: | Simplify the example for the test of deprecation warnings. → Use assertWarnsMessage() in the example of deprecation warnings. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
comment:4 by , 6 years ago
| Has patch: | set |
|---|
comment:5 by , 6 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
In 54a7b021: