Yelp / Testify

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

on failure during [class_]setup, stop running additional setups #208

Closed mrtyler closed 10 years ago

mrtyler commented 10 years ago

This arose due to internal bug #58087, but this branch fixes the now preschool-aged issue #12 (achievement unlocked; waves to @ayust).

import testify as T

class A(T.TestCase):

    @T.class_setup
    def first(self):
        print "first"
        raise Exception

class B(A):

    @T.class_setup
    def second(self):
        print "second"

    def test_me(self):
        print "this won't run"

if __name__ == '__main__':
    T.run()

results in the following output with Testify 0.4.2:

first
second
error: B.test_me
Traceback (most recent call last):
  File "/usr/lib/python2.6/contextlib.py", line 16, in __enter__
    return self.gen.next()
  File "/usr/lib/python2.6/dist-packages/testify/test_case.py", line 371, in wrapper
    fixture()
  File "test_class_setup_test_case.py", line 9, in first
    raise Exception
Exception

With this branch, we instead get:

first
error: B.test_me
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Users/tyler/Testify/testify/test_fixtures.py", line 73, in wrapper
    fixture()
  File "tmp.py", line 9, in first
    raise Exception
Exception

There are now unit tests pinning down the order in this and a few other exceptional situations.

ayust commented 10 years ago

Woo. :)

blampe commented 10 years ago

Looks good to me!