Opened 4 years ago

Last modified 4 years ago

#9266 enhancement new

trial should mark logged but unflushed errors as such

Reported by: mark williams Owned by:
Priority: normal Milestone:
Component: trial Keywords:
Cc: Allison Kaptur Branch:
Author:

Description

trial reports logged failures that were not flushed with flushLoggedErrors as a test failure. Unfortunately it doesn't indicate that these failures were logged, leading to confusing test output.

Consider:

from twisted.trial import unittest
from twisted.logger import Logger
from twisted.python.failure import Failure

class UnderTest(object):
    log = Logger()

    def method(self):
        try:
            raise Exception
        except:
            self.log.failure("what", failure=Failure())


class ExampleTest(unittest.SynchronousTestCase):

    def test_logging(self):
        UnderTest().method()

trial's output indicates a failure:

module 
  ExampleTest
    test_logging ...                                                    [ERROR]

===============================================================================
[ERROR]
Traceback (most recent call last):
  File "/path/to/module.py", line 11, in method
    raise Exception
exceptions.Exception: 

module.ExampleTest.test_logging
-------------------------------------------------------------------------------
Ran 1 tests in 0.123s
FAILED (errors=1)

The output does not indicate that it's an unflushed, logged exception, since it only includes the ERROR status and a traceback. This is confusing unless you're accustomed to the overly terse output.

When reporting an error that's due to an unflushed, logged exception, trial should mention as much.

See https://github.com/twisted/treq/issues/205.

Change History (2)

comment:1 Changed 4 years ago by Allison Kaptur

Cc: Allison Kaptur added

comment:2 Changed 4 years ago by Glyph

I think this may be at least tangentially related to #2365, in that it affects how Trial formats its output messages.

Note: See TracTickets for help on using tickets.