Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLTestRunner.py has a bug #20

Open
onesbyones opened this issue Aug 7, 2017 · 0 comments
Open

HTMLTestRunner.py has a bug #20

onesbyones opened this issue Aug 7, 2017 · 0 comments

Comments

@onesbyones
Copy link

onesbyones commented Aug 7, 2017

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant