Skip to content

Unexpected Success not handled gracefully #288

@silkehorn

Description

@silkehorn

The following script fails:

import unittest import xmlrunner class ExampleTestCase(unittest.TestCase): @unittest.expectedFailure def test_unexpected_success(self): self.assertTrue(True) if __name__ == "__main__": # Run tests with xmlrunner and output the results as XML with open('test-reports/results.xml', 'wb') as output: unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) 

This is the output:

Running tests... ---------------------------------------------------------------------- u ====================================================================== Traceback (most recent call last): File "simpletest.py", line 13, in <module> unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output)) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/main.py", line 102, in __init__ self.runTests() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/main.py", line 274, in runTests self.result = testRunner.run(self.test) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/xmlrunner/runner.py", line 72, in run result.printErrors() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/runner.py", line 149, in printErrors self.stream.writeln(f"UNEXPECTED SUCCESS: {self.getDescription(test)}") ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/runner.py", line 47, in getDescription doc_first_line = test.shortDescription() ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'tuple' object has no attribute 'shortDescription' 

It seems that unittest expects a scalar test, but gets a tuple (test, "unexpected success").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions