Omar Diab added the comment:

I found out about this while writing my own test runner, and investigated it in 
an answer to a StackOverflow question here: 
https://stackoverflow.com/questions/32920025/how-do-i-use-unittest-testresult/33770125#33770125

The startTestRun() method is supposed to be called at the beginning of a test 
run. That mostly works, but if you run a TestCase.run() method—or 
TestSuite.run(), because it just calls TestCase.run()—it will only call that 
method if you don't provide a TestResult instance. That means the lifecycle 
method is useless in those cases, because the default TestResult.startTestRun() 
method is a no-op.

This is how unittest.TestCase.run() starts:

def run(self, result=None):
    orig_result = result
    if result is None:
        result = self.defaultTestResult()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()
    # ...

The branch for calling startTestRun() is inside the `if result is None` check, 
making it never get called with an implementation of startTestRun().

This is currently mitigatable by just calling startTestRun() manually. But the 
documentation makes it seem like this lifecycle method should be called 
automatically, when it is not.

----------
nosy: +Omar Diab

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18848>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to