Merge lp:~jml/launchpad/show-warnings-once into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 11308
Proposed branch: lp:~jml/launchpad/show-warnings-once
Merge into: lp:launchpad
Diff against target: 32 lines (+6/-3)
1 file modified
lib/lp/scripts/utilities/warninghandler.py (+6/-3)
To merge this branch: bzr merge lp:~jml/launchpad/show-warnings-once
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+31831@code.launchpad.net

Commit message

Only show warnings once at the end of a test run.

Description of the change

It turns out that we blat all over Python's normal warning filtering and show every instance of every warning. This sucks *and* blows at the same time, so I've cobbled together a crappy little hack to fix it.

It's pretty hard to verify that this hack works, so I'm running the branch through ec2 test now.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

If it works, rs=me

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Because the warnings include repr()'s this doesn't help in a lot of situations, e.g.:

/var/launchpad/test/lib/lp/soyuz/tests/test_publishing.py:229: ShouldThisBeUsingRemoveSecurityProxy: removeSecurityProxy(<PackageUpload at 0x16f126d0>) called. Is this correct? Either call it directly or fix the test.
  package_upload)

/var/launchpad/test/lib/lp/soyuz/tests/test_publishing.py:229: ShouldThisBeUsingRemoveSecurityProxy: removeSecurityProxy(<PackageUpload at 0x146b2210>) called. Is this correct? Either call it directly or fix the test.
  package_upload)

I guess we should make sure to improve our __repr__ methods to fix more of these.

Either way, it's better than using a list. Should it perhaps be sorted so we see the warnings grouped per file, line?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/scripts/utilities/warninghandler.py'
--- lib/lp/scripts/utilities/warninghandler.py 2010-07-27 13:56:42 +0000
+++ lib/lp/scripts/utilities/warninghandler.py 2010-08-05 15:19:50 +0000
@@ -147,7 +147,9 @@
147147
148need_page_titles = []148need_page_titles = []
149no_order_by = []149no_order_by = []
150other_warnings = []150
151# Maps (category, filename, lineno) to WarningReport
152other_warnings = {}
151153
152old_show_warning = warnings.showwarning154old_show_warning = warnings.showwarning
153def launchpad_showwarning(message, category, filename, lineno, file=None,155def launchpad_showwarning(message, category, filename, lineno, file=None,
@@ -177,7 +179,8 @@
177 WarningReport(warning_message, important_info)179 WarningReport(warning_message, important_info)
178 )180 )
179 return181 return
180 other_warnings.append(WarningReport(warning_message, important_info))182 other_warnings[(category, filename, lineno)] = WarningReport(
183 warning_message, important_info)
181184
182def report_need_page_titles():185def report_need_page_titles():
183 global need_page_titles186 global need_page_titles
@@ -202,7 +205,7 @@
202 if other_warnings:205 if other_warnings:
203 print206 print
204 print "General warnings."207 print "General warnings."
205 for warninginfo in other_warnings:208 for warninginfo in other_warnings.itervalues():
206 print209 print
207 print warninginfo210 print warninginfo
208211