Reputation: 5839
I am currently using this self.assertTrue(True)
to pass the test. What I want is to pass a test if a specific warning is raised.
import warnings
class test(unittest.TestCase):
def test_1(self):
with warning.catch_warnings(record=False):
warning.simplefilter("error", category=CustomWarning)
try: function_that_raisesCustomWarning()
except CustomWarning as w: self.assertTrue(True)
Upvotes: 5
Views: 1210
Reputation: 6794
A test always passes, in case there is no indication that it failed. Just don't do anything in case everything is alright.
Upvotes: 8