mercredi 4 mai 2016

How determine if a TestCase failed in Python 2.7

In Chapter 20 of Harry Percival's Test-Driven Development with Python, there is a function to determine whether or not a TestCase has failed so it can take a screenshot:

# StaticLiveServerTestCase is a descendant of unittest.TestCase
class FunctionalTest(StaticLiveServerTestCase):
    def tearDown(self):
        if self._test_has_failed():
            # ... snipped for brevity
        self.browser.quit()
        super().tearDown()


    def _test_has_failed(self):
        for method, error in self._outcome.errors:
            if error:
                return True
        return False

This _outcome property is implemented on the TestCase class in Python 3.4, but not in Python 2.7. Is there some way I can determine whether or not a TestCase had an error in Python 2.7?

Aucun commentaire:

Enregistrer un commentaire