[TIP] Seeking testing framework for code that cannot be tested by Python unittest
Goldberg, Arthur P
arthur.p.goldberg at mssm.edu
Wed Jun 22 20:24:02 PDT 2016
I’ve extensive experience using Python unittest. However, I’ve some new code that I cannot test with unittest because the assertions must be applied in a derived class (call it class X) that contains methods executed by an application layer scheduler. Thus, tests of this code cannot be written as methods named test*() in a class derived from unittest.TestCase.
I attempted to address this problem by using pytest, because it is easy to write assert statements in class X. However, pytest doesn’t find the assert statements. Rather it reports “collected 0 items”.
Investigating further, I ran pytest —debug. In a cryptic, 700+ line log file it reports “message: cannot collect test class 'TestSimulationObject' because it has a __init__ constructor”. This doesn’t make sense. Python classes almost always use an __init__ constructor. Nevertheless, I tried removing the class X’s __init__() constructor and initializing its attributes through another method. But pytest —debug still reports the same message in the debug log.
My primary interest is to automate the testing of class X. It would be nice if that could be done with Python unittest by making direct calls to the TestCase API but I suspect that would require more effort than I want to devote to solving this problem. Probably the best approach would be to use another testing framework that offers similar flexibility to pytest, but does indeed test Class X.
Please let me know what you think or recommend.
Arthur Goldberg, PhD
Associate Professor of Genetics and Genomic Sciences
Icahn Institute for Genomics & Multiscale Biology
Icahn School of Medicine at Mount Sinai
646 526 5020
Arthur.Goldberg at mssm.edu<mailto:Arthur.Goldberg at mssm.edu>
Follow us on Twitter @IcahnInstitute<https://twitter.com/IcahnInstitute>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python