Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 André Ericson, 5 years ago

Owner: changed from nobody to André Ericson
Status: newassigned

comment:2 by André Ericson, 5 years ago

Summary: Simplify example of test of deprecation warning.Simplify the example for the test of deprecation warnings.

comment:3 by Mariusz Felisiak, 5 years ago

Summary: Simplify the example for the test of deprecation warnings.Use assertWarnsMessage() in the example of deprecation warnings.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:4 by Mariusz Felisiak, 5 years ago

Has patch: set

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 54a7b021:

Fixed #30927 -- Simplified an example of test for the deprecation warning with assertWarnsMessage().

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 3c5f8313:

[3.0.x] Fixed #30927 -- Simplified an example of test for the deprecation warning with assertWarnsMessage().

Backport of 54a7b021125d23a248e70ba17bf8b10bc8619234 from master

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 972eef6b:

[2.2.x] Fixed #30927 -- Simplified an example of test for the deprecation warning with assertWarnsMessage().

Backport of 54a7b021125d23a248e70ba17bf8b10bc8619234 from master

Note: See TracTickets for help on using tickets.
Back to Top