Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python's unittest `assertCouldNotTest`?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading