suppress warnings when testing deprecated interfaces

Bug #43931 reported by Martin Pool
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Aaron Bentley

Bug Description

> > The test suite prints all deprecation warnings on the error output. But isn't
> > it supposed to test deprecated interfaces as long as they are kept around?
>
> Whenever an interface becomes deprecated, none of the core code should
> use it. Printing deprecation warnings during test runs is a good way to
> catch that when it does happen.
>
> It's hard to distinguish between tests of deprecated functions and tests
> of undeprecated functions that happen to call deprecated functions,
> which means we're getting error output even for deprecations warnings we
> expect.
>
> Perhaps we need a decorator to suppress expected deprecations warnings
> for test cases that exercise deprecated interfaces.

Something like

def test_deprecated_function():
  warnings.filterwarnings('ignore', 'frob_thing is deprecated.*')
  try:
    frob_thing(3)
  finally:
    unfilter_it()

On a brief look at the warnings module there isn't a clear way to remove
just the one specific filter we had put in place, but it can probably be
done, by brute force if necessary.

Also we should probably make a UserWarning subclass for deprecations.

Or perhaps more simply, the test case for a class can just filter out
all deprecation warnings for calls to deprecated methods of the class
directly from the test:

  warnings.filterwarnings('ignore', 'SomeClass.* is deprecated',
                          DeprecationWarning, 'test_some_class')

and then not worry about pulling it out. I have not tested yet if this
works.

Revision history for this message
John A Meinel (jameinel) wrote :

Aaron added the test suite function TestCase.callDeprecated(), which will call a deprecated function, and assert that it does, in fact, cause deprecation warnings, but will prevent them from being written to the screen.

Changed in bzr:
assignee: nobody → aaron-bentley
status: Unconfirmed → Fix Released
Martin Pool (mbp)
tags: added: api-versioning
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.