Skip to content Skip to sidebar Skip to footer

How To Fail A Python Unittest In Setupclass?

I am doing some unittests with python and some pre-test checks in setUpClass. How can I throw a unitest-fail within the setUpClass, as the following simple example: class MyTests(u

Solution 1:

self.fail("test") put into your setUp instance method fails all the tests

I think the easiest way to do this at the class level is to make a class variable so something like:

@classmethoddefsetUpClass(cls):
   cls.flag = FalsedefsetUp(self):
   if self.flag:
       self.fail("conditions not met")

Hope this is what you want.

Solution 2:

Using a simple assert should work

assertFalse, "I mean for this to fail"

Post a Comment for "How To Fail A Python Unittest In Setupclass?"