SPONSORS:






User Tag List

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Jan 2003
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Do...Except Blocks in a main() function

    Is it possible to do something like the following in a testcase:

    main ()
    do
    test1()
    test2 ()
    except
    print("A testcase failed")

    testcase test1()
    blah blah

    testcase test2()
    blah blah


    I have tried this but it does not seem to catch the exceptions thrown by the testcases. Are there any special consideration needed to do this?


    Thanks.

    ------------------

  2. #2
    Senior Member
    Join Date
    Aug 2001
    Location
    Manchester, NH
    Posts
    121
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Do...Except Blocks in a main() function

    I don't think the do...except will work in that case, though the testcase might fail, it doesn't return an exception back to main(). I'd use GetTestsFailedCount() to see if a test has failed, you should be able to accomplish the same thing with that.

    ------------------
    Adam Kuczkowski
    akuczkowski@frametech.com

  3. #3
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Do...Except Blocks in a main() function

    No, I believe it's impossible. Any exception thrown within a testcase is dealt with in the TestcaseExit function.
    I don't know if it' possible to alter TestcaseExit so it doesn't deal with exceptions, so the testplan would have to deal with them; but I wouldn't like to try it.

    ------------------

  4. #4
    Junior Member
    Join Date
    Sep 2001
    Location
    Mountain View, CA
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Do...Except Blocks in a main() function

    That's correct, you need to write your own TestCaseExit () and put the do/except handling there. You can even trap specific exception numbers and write out different (more helpful) error messages if need be.

    ------------------

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Location
    UK, Oxford
    Posts
    150
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Do...Except Blocks in a main() function

    Ok, so you can reraise the exception:
    this way the exception is propagated outside the testcase.

    so given the following testcases:
    You could write a main function:

    where execution would stop after fred(exception is raised in fred testcase) but continue with barney.
    This could be useful where, given a grouping of testcases specific to a certain aspect of the AUT, you do not want subsequent testcases to run should there be any failures. So when fred fails, I definitely do not want to bother attempting to run bambam and wilma, but I do want the rubble tests to run.

    Obviously, if you do this sort of thing it means that you could no longer run a script of testcases from top to bottom (which is the default behaviour) because if one crashed out execution of the script would stop, but that's OK, you could build in conditional behaviour to TestCaseExit.

    The only other problem is this:
    Have I got the cave kids with the right families or are they mutually babysitting...?

    ------------------


    [This message has been edited by johntest (edited 02-13-2003).]
    Tempus fugit, Carpe Diem, et al

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:15 AM.

Copyright BetaSoft Inc.