[issue16288] TextTestResult uses TestCase.__str__() which isn't customisable (vs id() or shortDescription())

Chris Jerdonek report at bugs.python.org
Sat Oct 20 17:09:28 CEST 2012


Chris Jerdonek added the comment:

> So the relevant code is this:
> def getDescription(self, test):
> ...
> 43 return str(test)
> ...
> What I'd like is to have this be something like:
> 44     return test.id()

> Or anther way this could be done would be to make TestCase.__str__ call self.id()

Note that str(test) and test.id() don't return the same value.  The former is the "friendly" name.  It is probably intentional that TextTestResult uses the TestCase instance's friendly name in its getDescription() method as opposed to the id.

> TextTestRunner calls str(TestCase) directly, which makes it hard for testscenarios to rename the test cases as it parameterises them

What about testscenarios subclassing the TestCase instances as it parametrizes them?

    class ScenariosTestCase(case.__class__):
        def __str__(self):
            return "testscenarios test name..."
    case.__class__ = ScenariosTestCase
    print(str(case))

>From the documentation, it looks like testscenarios creates new test objects from the originals anyways.  Alternatively (although I don't if testscenarios can control what test runner is being used), TextTestRunner could be subclassed with its own getDescription() method.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16288>
_______________________________________


More information about the Python-bugs-list mailing list