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

Return result that supports wasSuccessful() #283

Open
HorstBaerbel opened this issue Mar 20, 2024 · 0 comments
Open

Return result that supports wasSuccessful() #283

HorstBaerbel opened this issue Mar 20, 2024 · 0 comments

Comments

@HorstBaerbel
Copy link

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.

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