Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My coworker Chris came up with this, and it works, but I wonder if there's a more "official" way to do this using unittest.TestCase in Python.

def tearDown(self):
    """ clean up by closing the browser window """
    if sys.exc_info() == (None, None, None):  # leave window open on fail
share|improve this question

I don't know if this will work for pyunit but in Robot Framework, you can access singletons which represent the test suite and test case during the run. May be the unittest runner you are using provides the same functionality instead of having to inspect the stack.

share|improve this answer
Good point. I know nunit recently added a TestContext that allows you to determine whether the most recent test passed or failed. – Sam Woods Oct 24 '12 at 21:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.