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

Unexpected Success not handled gracefully #288

Open
silkehorn opened this issue Jan 17, 2025 · 1 comment
Open

Unexpected Success not handled gracefully #288

silkehorn opened this issue Jan 17, 2025 · 1 comment

Comments

@silkehorn
Copy link

silkehorn commented Jan 17, 2025

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").

@silkehorn
Copy link
Author

This would be fixed by #274...

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