Yelp / Testify

A more pythonic testing framework.
Other
306 stars 67 forks source link

test setup/teardown's continue to run after class setup has failed. #220

Closed bukzor closed 10 years ago

bukzor commented 10 years ago

I have a patch for this already. Incoming shortly.

Instrumenting the "instance" setup/teardown in the case of class setup failure reveals the issue: The test methods are not run, but the test instance setup/teardowns are run where the methods would have run.

========================================================================
test.test_case_test ExceptionDuringClassSetupTest.test_child
------------------------------------------------------------
Traceback (most recent call last):
  File "./test/test_case_test.py", line 440, in test_child
    assert_equal(expected, test_case.run_methods)
AssertionError: assertion failed: l == r
l: ['parent class_setup', 'child class_teardown', 'parent class_teardown']
r: ['parent class_setup', 'parent setup', 'child teardown', 'parent teardown', 'parent setup', 'child teardown', 'parent teardown', 'child class_teard
own', 'parent class_teardown']

Diff:
l: ['parent class_setup', 'child class_teardown', 'parent class_teardown']
r: ['parent class_setup', 'parent setup', 'child teardown', 'parent teardown', 'parent setup', 'child teardown', 'parent teardown', 'child class_teard
own', 'parent class_teardown']

========================================================================

========================================================================
test.test_case_test ExceptionDuringClassSetupTest.test_parent
------------------------------------------------------------
Traceback (most recent call last):
  File "./test/test_case_test.py", line 434, in test_parent
    assert_equal(expected, test_case.run_methods)
AssertionError: assertion failed: l == r
l: ['parent class_setup', 'parent class_teardown']
r: ['parent class_setup', 'parent setup', 'parent teardown', 'parent class_teardown']

Diff:
l: ['parent class_setup', 'parent <>class_teardown']
r: ['parent class_setup', 'parent <setup', 'parent teardown', 'parent >class_teardown']

========================================================================
diff --git a/test/test_case_test.py b/test/test_case_test.py
index c92f955..2c4b6a4 100644
--- a/test/test_case_test.py
+++ b/test/test_case_test.py
@@ -386,27 +386,44 @@ class ExceptionDuringClassSetupTest(TestCase):
             super(ExceptionDuringClassSetupTest.FakeParentTestCase, self).__init__(*args, **kwargs)

         @class_setup
-        def parent_setup(self):
+        def parent_class_setup(self):
             self.run_methods.append("parent class_setup")
             raise Exception

         @class_teardown
-        def parent_teardown(self):
+        def parent_class_teardown(self):
             self.run_methods.append("parent class_teardown")

+        @setup
+        def parent_setup(self):
+            self.run_methods.append("parent setup")
+            raise Exception
+
+        @teardown
+        def parent_teardown(self):
+            self.run_methods.append("parent teardown")
+
         def test_parent(self):
             self.run_methods.append("parent test method")

     class FakeChildTestCase(FakeParentTestCase):

         @class_setup
-        def child_setup(self):
+        def child_class_setup(self):
             self.run_methods.append("child class_setup")

         @class_teardown
-        def child_teardown(self):
+        def child_class_teardown(self):
             self.run_methods.append("child class_teardown")

+        @setup
+        def child_setup(self):
+            self.run_methods.append("child setup")
+
+        @teardown
+        def child_teardown(self):
+            self.run_methods.append("child teardown")
+
         def test_child(self):
             self.run_methods.append("child test method")