Re: unittest exits

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Rebert

    Re: unittest exits

    On Thu, Nov 13, 2008 at 11:01 AM, Alan Baljeu <alanbaljeu@yah oo.comwrote:
    When I call unittest.main() , it invokes sys.exit(). I would like to run tests without exiting. How can I?
    There's probably a better way that stops it from trying to exit in the
    first place, but here's a quick kludge:

    try:
    unittest.main()
    except SystemExit:
    pass

    sys.exit() does its job by noting the return code and then raising the
    SystemExit exception, which you are free to catch.

    Cheers,
    Chris
    --
    Follow the path of the Iguana...

    >
    >
    Alan Baljeu
    >
    >
    _______________ _______________ _______________ _______________ ______
    Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
    --

    >
  • jhermann

    #2
    Re: unittest exits

    On 13 Nov., 20:20, "Chris Rebert" <c...@rebertia. comwrote:
    try:
        unittest.main()
    except SystemExit:
        pass
    You most probably want this instead:

    try:
    unittest.main()
    except SystemExit, exc:
    # only exit if tests failed
    if exc.code:
    raise

    Comment

    Working...