Ticket #2703 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

assertWarns has some restrictions

Reported by: therve Owned by: therve
Priority: highest Milestone:
Component: core Keywords:
Cc: exarkun Branch:
Author: Launchpad Bug:

Description (last modified by therve) (diff)

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

Changed 3 years ago by therve

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

Ready to review in assertwarns-features-2703.

Changed 3 years ago by jml

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

Changed 3 years ago by therve

  • description modified (diff)

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

Changed 3 years ago by exarkun

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

Changed 3 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.

Changed 3 years ago by therve

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

Changed 3 years ago by exarkun

  • 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 ''
-------------------------------------------------------------------------------

Changed 3 years ago by therve

  • keywords review added
  • owner therve deleted
  • cc exarkun added

Damn, sorry, that was something stupid.

Changed 3 years ago by exarkun

  • owner set to therve
  • keywords review removed

No problem. Looks great, please merge :)

Changed 3 years ago by therve

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

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

Note: See TracTickets for help on using tickets.