Skip to content

Return result that supports wasSuccessful() #283

Description

@HorstBaerbel

When running xmlrunner through unittest.main() and passing exit=False, unittest will not set a result code, but sets self.result to the xmrunner result. Because xmlrunner does not return a result compatible with unittest.TestResult there is no good way to check if the run was ok. When checking unittest.result.wasSuccessful() you get "AttributeError: module 'unittest.result' has no attribute 'wasSuccessful'".

Example:

import io
import sys
import unittest
import xmlrunner

def unittestProxy():
        # run the tests storing results in memory
        xmlBytes = io.StringIO()
        xmlRunner=xmlrunner.XMLTestRunner(output=xmlBytes, outsuffix='')
        unittest.main(testRunner=xmlRunner, failfast=False, buffer=False, catchbreak=False, exit=False)
        #...processing xmlBytes here.....
        # store result in XML file
        with open(resultFileName, 'w') as resultFile:
            resultFile.write(xmlBytes)
        # get exit code from unittest run (broken atm)
        sys.exit(not unittest.result.wasSuccessful())

if __name__ == '__main__':
    unittestProxy()

If there's a good workaround please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions