Opened 8 years ago

Closed 6 years ago

#2820 defect closed fixed (fixed)

trial warning reporting uses print to stdout

Reported by: exarkun Owned by: jonathanj
Priority: highest Milestone:
Component: trial Keywords:
Cc: Branch: branches/leaky-warnings-2820
(github, patch, buildbot, log)
Author: jonathanj Launchpad Bug:


See twisted/trial/

Using print means that the warning might not actually be reported, since print can fail with EINTR. It also means that what was once structured information (this is a warning, this is the message format string, these are the arguments) becomes unstructured data in a log file; sometimes this is desirable, but it should probably be up to a reporter what is done with the message, not the runner.

Change History (14)

comment:1 Changed 8 years ago by glyph

See duplicate #3070

comment:2 Changed 8 years ago by glyph

See related ticket #2365

comment:3 Changed 7 years ago by exarkun

#3433 was a duplicate of this.

comment:4 Changed 7 years ago by exarkun

  • Priority changed from normal to highest

comment:5 Changed 7 years ago by exarkun

  • Owner changed from jml to exarkun
  • Status changed from new to assigned

comment:6 Changed 7 years ago by exarkun

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

(In [25279]) Merge flushwarnings-3487

Author: radix, itamar, exarkun Reviewer: glyph Fixes: #3487 Fixes: #3427 Fixes: #2820 Fixes: #3506

Introduce TestCase.flushWarnings, an API for interacting with the Python warnings module in unit tests. By default, the default trial reporter will write warnings emitted by tests to its output stream (no longer does the runner print them to stdout). flushWarnings may be used to prevent this from happening in particular tests, and its return value may be used to make assertions about what warnings have been emitted. TestCase.assertWarns and TestCase.callDeprecated are both now implemented in terms of this more flexible API.

The default reporter includes rudamentary support for duplicate suppression: each warning will be reported only once per test, but if a warning is emitted by two or more tests, it will be reported for each test (isolating tests from each other further by making warning behavior the same regardless of what other tests have run).

There is also some support for failing tests based on warnings emitted. If the Python warnings filters system is used to turn a warning into an exception, any test which causes such a warning to be emitted will have an error attributed to it.

comment:7 Changed 7 years ago by exarkun

  • Resolution fixed deleted
  • Status changed from closed to reopened

Apparently this wasn't really fixed. :(

exarkun@charm:~$ trial twisted.test.test_log.LogTest.test_showwarning
    test_showwarning ... FakeWarning: unique warning message

Ran 1 tests in 0.002s

PASSED (successes=1)

comment:8 Changed 6 years ago by jonathanj

  • Author set to jonathanj
  • Branch set to branches/leaky-warnings-2820

(In [27219]) Branching to 'leaky-warnings-2820'

comment:9 Changed 6 years ago by jonathanj

(In [27220]) Make log.showwarning a method of LogPublisher and use a private log publisher for test_showwarning, to avoid other observers from polluting stdout, refs #2820.

comment:10 Changed 6 years ago by jonathanj

  • Keywords review added
  • Owner exarkun deleted
  • Status changed from reopened to new

comment:11 Changed 6 years ago by exarkun

  • Keywords review removed
  • Owner set to jonathanj

Okay, great. It looks like this ticket was mostly resolved by the previous branch. Only the tests needed the slight tweak in this new branch to avoid spitting ugly crap into the output. The change makes sense and looks good. Please update the copyright date on both modified files and then merge.

comment:12 Changed 6 years ago by jonathanj

(In [27224]) Update copyright dates, refs #2820.

comment:13 Changed 6 years ago by jonathanj

(In [27225]) Update the other copyright date, refs #2820.

comment:14 Changed 6 years ago by jonathanj

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

(In [27226]) Merge leaky-warnings-2820 branch.

Author: jonathanj Revewer: exarkun Fixes: #2820

Tweak the tests for "showwarning" to avoid emitting a log message to all the normal observers, some of which simply print warnings to stdout, causing ugly spew in trial's output.

Note: See TracTickets for help on using tickets.