Opened 6 years ago

Closed 6 years ago

#3427 defect closed fixed (fixed)

twisted.trial.test.test_assertions.TestCallDeprecated.test_callDeprecatedSuppressesWarning overrides warnings.warn_explicit to catch emitted warnings

Reported by: exarkun Owned by:
Priority: normal Milestone: Python-2.6
Component: trial Keywords:
Cc: Branch:
Author: Launchpad Bug:

Description

This test tries to assert that no warnings are emitted when callDeprecated is used to call a function which emits a deprecation warning. It replaces warnings.warn_explicit for the duration of the test and expects to be able to observe warnings through its replacement. In Python 2.6, this strategy will not work. The test should likely use the strategy used in the implementation of TestCase.assertWarns (which perhaps should be factored into a general API, at least for internal-trial use).

Change History (3)

comment:1 Changed 6 years ago by exarkun

(In [24952]) reimplement callDeprecated in terms of flushWarnings; strengthen the assertion about ignored warnings

refs #3427

This likely resolved #3427 since it removes the use of warn_explicit from the mentioned test method.

comment:2 Changed 6 years ago by exarkun

  • Resolution set to fixed
  • Status changed from new to closed

(In [25279]) Merge flushwarnings-3487

Author: radix, itamar, exarkun
Reviewer: glyph
Fixes: #3487
Fixes: #3427
Fixes: #2820
Fixes: #3506

Introduce TestCase.flushWarnings, an API for interacting with the Python warnings
module in unit tests. By default, the default trial reporter will write warnings
emitted by tests to its output stream (no longer does the runner print them to
stdout). flushWarnings may be used to prevent this from happening in particular
tests, and its return value may be used to make assertions about what warnings have
been emitted. TestCase.assertWarns and TestCase.callDeprecated are both now
implemented in terms of this more flexible API.

The default reporter includes rudamentary support for duplicate suppression: each
warning will be reported only once per test, but if a warning is emitted by two or
more tests, it will be reported for each test (isolating tests from each other
further by making warning behavior the same regardless of what other tests have run).

There is also some support for failing tests based on warnings emitted. If the Python
warnings filters system is used to turn a warning into an exception, any test which
causes such a warning to be emitted will have an error attributed to it.

comment:3 Changed 4 years ago by <automation>

  • Owner jml deleted
Note: See TracTickets for help on using tickets.