Ticket #2626 enhancement closed fixed

Opened 7 years ago

Last modified 7 years ago

trial needs something to check DeprecationWarning

Reported by: therve Owned by:
Priority: highest Milestone:
Component: trial Keywords:
Cc: exarkun, jml, therve, ralphm Branch:
Author: Launchpad Bug:


There is a method in test_process.ProcessTestCase that asserts that a function call produce a warning. It's a bit like util.supress, but with checking the content of the warning, and I think that would be great for the deprecation policy.

Change History


Changed 7 years ago by jml

I've added something like this in the setUpClass-2303-2 branch (currently stalled due to lack of gtk1 support in feisty).


Changed 7 years ago by exarkun

  • cc exarkun added

Where in that branch is the relevant code? I looked around for a minute but I didn't see any likely candidates. I was going to split it out into a separate branch so we could go ahead with this without waiting for #2303.


Changed 7 years ago by jml

t.trial.util.collectWarnings. It isn't quite what's described, but it's the first step.


Changed 7 years ago by therve

Note that it's in the ireporter-2164 branch, no setUpClass-2303.


Changed 7 years ago by therve

  • owner changed from jml to therve


Changed 7 years ago by therve

  • priority changed from normal to highest
  • owner therve deleted
  • keywords review added
  • cc jml, therve added

Ready to review in assert-warn-2626.


Changed 7 years ago by exarkun

  • keywords review removed
  • owner set to therve

Looks nice. A few things:

  • No coverage for the code which suppresses the __warningregistry__ for the function being tested (covering that probably just involves using assertWarn twice with the same function)
  • I think args and kwargs should be *args and **kwargs. If this is a practical problem for someone, we can fix it later (by defining all the positional arguments with *args).
  • assertWarns closes matches the naming style of assertRaises
  • The function being tested might result in multiple warnings; there's no way to test such a function the way assertWarn works now. It'd be fine to defer that functionality to another ticket/time though.


Changed 7 years ago by therve

  • owner therve deleted
  • keywords review added

I've addressed the 3 points. The last functionality could be useful, but I don't think that's a high priority.


Changed 7 years ago by ralphm

  • cc ralphm added
  • owner set to therve
  • keywords review removed

Reviewed the last change set. Looking good. Please merge.

Maybe create a ticket for the latter point raised by exarkun?


Changed 7 years ago by therve

  • status changed from new to closed
  • resolution set to fixed

(In [20485]) Merge assert-warn-2626

Author: therve Reviewer: ralphm, exarkun Fixes #2626

Add an assertWarns method on unittest.TestCase that allows to check a warning is emitted when a function is called.


Changed 3 years ago by <automation>

  • owner therve deleted
Note: See TracTickets for help on using tickets.