user3205834
user3205834

Reputation: 11

pytest. execute all teardown modules

i have use funcargs in my tests:

def test_name(fooarg1, fooarg2):

all of them have pytest_funcarg__ factories, which returns request.cached_setup, so all of them have setup/teardown sections.

sometimes i have a problem with fooarg2 teardown, so i raise exception in here. in this case ignore all the others teardowns(fooarg1.teardown, teardown_module, etc) and just goes to pytest_sessionfinished section.

is there any option in pytest not to collect exceptions and execute all remaining teardowns functions?

Upvotes: 1

Views: 369

Answers (2)

hpk42
hpk42

Reputation: 23561

Are you using pytest-2.5.1? pytest-2.5 and in particular issue287 is supposed to have brought support for running all finalizers and re-raising the first failed exception if any.

Upvotes: 3

User
User

Reputation: 14853

In your teardown function you can catch the error and print it.

def teardown(): # this is the teardown function with the error
    try:
        # the original code with error
    except:
        import traceback 
        traceback.print_exc() # no error should pass silently

Upvotes: 0

Related Questions