0 votes
1 view
in Python by (47.8k points)

I want to write a test to establish that an Exception is not raised in a given circumstance.

It's straightforward to test if an Exception is raised ...

sInvalidPath=AlwaysSuppliesAnInvalidPath() self.assertRaises(PathIsNotAValidOne, MyObject, sInvalidPath)

... but how can you do the opposite?

Something like this I what I'm after ...

sValidPath=AlwaysSuppliesAValidPath() self.assertNotRaises(PathIsNotAValidOne, MyObject, sValidPath)

1 Answer

0 votes
by (107k points)

If you want to write a test to establish that an Exception is not raised in a given circumstance you can use the following piece of code:-

def run_test(self):

try:

myFunc()

except ExceptionType:

self.fail("myFunc()raised ExceptionType unexpectedly!")

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...