Opened 8 years ago

Closed 8 years ago

#2626 enhancement closed fixed (fixed)

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:

Description

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 (11)

comment:1 Changed 8 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).

comment:2 Changed 8 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.

comment:3 Changed 8 years ago by jml

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

comment:4 Changed 8 years ago by therve

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

comment:5 Changed 8 years ago by therve

  • Owner changed from jml to therve

comment:6 Changed 8 years ago by therve

  • Cc jml therve added
  • Keywords review added
  • Owner therve deleted
  • Priority changed from normal to highest

Ready to review in assert-warn-2626.

comment:7 Changed 8 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.

comment:8 Changed 8 years ago by therve

  • Keywords review added
  • Owner therve deleted

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

comment:9 Changed 8 years ago by ralphm

  • Cc ralphm added
  • Keywords review removed
  • Owner set to therve

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

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

comment:10 Changed 8 years ago by therve

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

(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.

comment:11 Changed 4 years ago by <automation>

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