0

I have a python script (main.py) that calls a method in another python script (tester.py) that performs a bunch of tests, using unittest framework, and returns. What exception does main.py look for in it's try, except block?

I've tried the following but the exception is never triggered.

try:
  tester.run()
except Exception, ex:
  print ex

According to the documentation it raises AssertionError. However, I've tried AssertionError, Exception, but neither work.

Any ideas.

6
  • it doesnt raise an exception ... where do you see that it does? it just returns a thing that tells you what passed and what failed ... Commented Mar 6, 2014 at 23:01
  • docs.python.org/2/library/unittest.html To make migrating existing test suites easier, unittest supports tests raising AssertionError to indicate test failure. However, it is recommended that you use the explicit TestCase.fail*() and TestCase.assert*() methods instead, as future versions of unittest may treat AssertionError differently. Commented Mar 6, 2014 at 23:07
  • exception AssertionError Raised when an assert statement fails. Commented Mar 6, 2014 at 23:11
  • Line 166 of case.py in the unittest source gives the following: faiureException = AssertionError Commented Mar 6, 2014 at 23:15
  • thats a testcase.. you are talking about a testrunner ... which simply returns information (it caches the exception and records the data as a failure) a test runner runs a suite of tests ... it wouldnt do much good to crash out on the first error Commented Mar 6, 2014 at 23:24

1 Answer 1

0

Depends on which exception is raised.

Method raising exception:

def some(self):
    try:
        msg = "My Exception"
        raise HTTPNotFound(msg)
    except Exception as e:
         raise e

Method catching exception

try:
    some()
except HTTPNotFound as e:
    print "Not found exception"
except Exception as e:
    print "Generic Exception"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.