Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (47.6k 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 (106k 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!")

Related questions

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

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...