Skip to content

HTMLTestRunner.py has a bug #20

Description

@onesbyones

@tungwaiyip

  • HTMLTestRunner for Version 0.8.3 has a Bug, follow code:

    TestResult = unittest.TestResult
    
    class _TestResult(TestResult):
        # note: _TestResult is a pure representation of results.
        # It lacks the output and reporting ability compares to unittest._TextTestResult.
    
        def __init__(self, verbosity=1):
            TestResult.__init__(self)
            '''this line start'''
            self.outputBuffer = StringIO.StringIO()
            '''this line end'''
            self.stdout0 = None
            self.stderr0 = None
            self.success_count = 0
            self.failure_count = 0
            self.error_count = 0
            self.verbosity = verbosity
    
            # result is a list of result in 4 tuple
            # (
            #   result code (0: success; 1: fail; 2: error),
            #   TestCase object,
            #   Test output (byte string),
            #   stack trace,
            # )
            self.result = []
            
        def startTest(self, test):
            TestResult.startTest(self, test)
            # just one buffer for both stdout and stderr
            stdout_redirector.fp = self.outputBuffer
            stderr_redirector.fp = self.outputBuffer
            self.stdout0 = sys.stdout
            self.stderr0 = sys.stderr
            sys.stdout = stdout_redirector
            sys.stderr = stderr_redirector

    this block code will create a report.html after testsuite end, but in the report.html's popup_window will rewrite outputbuffer. example:

image

  • Modify this bug, follow me

    move code self.outputBuffer = StringIO.StringIO() to

        def startTest(self, test):
            TestResult.startTest(self, test)
            # just one buffer for both stdout and stderr
            '''after modify start'''
            self.outputBuffer = StringIO.StringIO()
            '''after modify end'''
            stdout_redirector.fp = self.outputBuffer
            stderr_redirector.fp = self.outputBuffer
            self.stdout0 = sys.stdout
            self.stderr0 = sys.stderr
            sys.stdout = stdout_redirector
            sys.stderr = stderr_redirector

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions