pythonnose2

How to check test run results in nose2?


With unittest I can check if there were failed tests during test run like this:

import unittest

all_tests = unittest.defaultTestLoader.discover('path-to-tests')
results = unittest.TextTestRunner().run(all_tests)
if results.wasSuccessful():
    do_something()
else:
    do_something_else()

How to do the same with nose2?


Solution

  • Finally found an answer.

    import nose2
    
    test_run = nose2.discover(argv = ['-s', 'path-to-tests'], exit = False)
    if test_run.result.wasSuccessful():
        do_something()
    else:
        do_something_else()