I am using Python’s unittest module to do some testing that some probability density functions that I have implemented integrate to 1. To test this I am using Scipy’s quad function:
integral, err = integrate.quad(my_pdf, -float('inf'), float('inf'))
self.assertTrue(isclose(integral, 1))
where isclose is from Python’s math. For some PDFs it happens that err is > 1 and integral is "very far from 1" such as I would consider this a fail. However this is not a fail of my_pdf but a fail of the testing method. To avoid flagging this as a fail I can do
if err > 1:
continue
but in this case I completely skipping this case without any clue that it happened.
Is it possible to somehow flag this kind of failure within unittest? Somthing like
if err > 1:
self.couldNotTest()
such that in the end unittest will tell me the number of tests that could not be performed?
>Solution :
This sound sketchy overall (If pdfs with integrals very far from 1 are unsupported, and that’s expected, then why are you attempting to test them, in the first place?)
In any case, I think you’re looking for TestCase.skipTest