Opened 15 years ago

Closed 15 years ago

#2703 enhancement closed fixed (fixed)

assertWarns has some restrictions

Reported by: therve Owned by:
Priority: highest Milestone:
Component: core Keywords:
Cc: Jean-Paul Calderone Branch:
Author:

Description (last modified by therve)

First uses of assertWarns have shown some limits:

  • it can't be used to check warnings emitted by class instantiation or implicit __call__ method
  • it doesn't work with warnings filtered by default like PendingDeprecationWarning

Change History (11)

comment:1 Changed 15 years ago by therve

Keywords: review added
Owner: therve deleted
Priority: normalhighest

Ready to review in assertwarns-features-2703.

comment:2 Changed 15 years ago by Jonathan Lange

What exactly do you mean by "it can't be used with class"?

comment:3 Changed 15 years ago by therve

Description: modified (diff)

I've modified the description to reflect what I meant.

comment:4 Changed 15 years ago by Jean-Paul Calderone

Arg, I hate the stupid warnings module.

Noble effort, but the only actually correct way to get __warningsregistry__ is to go through the same dance as warnings.warn. Even if we duplicate it, there's no guarantee Python devs won't change it randomly for the next release.

I'm trying to remember why we don't do something like patch warnings.warn_explicit instead of trying to re-assemble the events after the fact. I think the reason we didn't patch warnings.warn was to support from warnings import warn, but I can't think of a similar reason not to patch warn_explicit.

(This is not a review, just some thoughts.)

comment:5 Changed 15 years ago by therve

We dont't patch warn_explicit because we didn't implemented like that at the beginning :). I guess that could work though.

comment:6 Changed 15 years ago by therve

I've tried it, and it's too good to be true :).

comment:7 Changed 15 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to therve

Hmm, for me, some tests in twisted.trial.test.test_tests fail w/ this branch merged into trunk, mostly similar to this:

===============================================================================
[FAIL]: twisted.trial.test.test_tests.SuppressionTest.testSuppressModule

Traceback (most recent call last):
  File "/home/exarkun/Projects/Twisted/trunk/twisted/trial/test/test_tests.py", line 507, in testSuppressModule
    self.assertSubstring(suppression.METHOD_WARNING_MSG, self.getIO())
  File "/home/exarkun/Projects/Twisted/trunk/twisted/trial/unittest.py", line 307, in failUnlessSubstring
    return self.failUnlessIn(substring, astring, msg)
twisted.trial.unittest.FailTest: 'method warning message' not in ''
-------------------------------------------------------------------------------

comment:8 Changed 15 years ago by therve

Cc: Jean-Paul Calderone added
Keywords: review added
Owner: therve deleted

Damn, sorry, that was something stupid.

comment:9 Changed 15 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to therve

No problem. Looks great, please merge :)

comment:10 Changed 15 years ago by therve

Resolution: fixed
Status: newclosed

(In [20610]) Merge assertwarns-features-2703

Author: therve Reviewer: exarkun Fixes #2703

Fix implementation of assertWarns to work with all callables and with all type of warnings.

comment:11 Changed 11 years ago by <automation>

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