[TIP] Seeking testing framework for code that cannot be tested by Python unittest

Goldberg, Arthur P arthur.p.goldberg at mssm.edu
Thu Jun 23 09:26:26 PDT 2016


Hi Rob

Yes, I have that impression about unittest, but could not locate documentation which teaches me how to use it to test my code.

The system I want to test is a discrete event simulator. Its primary components are a simulation engine and a set of simulation objects which represent the components of the system being modeled.
The initialization of a simulation program creates the simulation objects, each of which registers with the engine. Initialization must also create at least one event. Events are stored in the engine. The simulation is started by executing the engine’s scheduler method.
The scheduler repeatedly chooses the next event and calls the event handler in the simulation object that receives the event. The event handler can schedule future events for any simulation object, including itself. The simulation ends when it runs out of events to process, exceeds a termination time, or fails.
My tests use some real simulation objects and some test simulation objects. They exchange events with each other. I want the test objects to verify assertions about the state of the events they receive from the real simulation objects.

I can show you code if that would help.

Thanks very much
Arthur

On Jun 22, 2016, at 11:32 PM, Robert Collins <robertc at robertcollins.net> wrote:

unittest doesn't care about inheritance much (the loader cares, but
nothing else) - but I don't understand when you say 'must be
written... in class X'.

Can you give some more detail about why that is ? E.g. its a GUI
framework and you want to have your assertion take place in response
to a GUI event?

-Rob

On 23 June 2016 at 15:24, Goldberg, Arthur P <arthur.p.goldberg at mssm.edu> wrote:
Hello

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.
Thanks
Arthur

---

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
Karr Lab
Arthur.Goldberg at mssm.edu
Follow us on Twitter @IcahnInstitute





_______________________________________________
testing-in-python mailing list
testing-in-python at lists.idyll.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.idyll.org_listinfo_testing-2Din-2Dpython&d=AwIFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=YJ-P8A_IxL3Zjky1E-3bFdXBuYKHfErI7GLYVgHRY7I&s=05Ldl4firRTVfeTf5Ad0_M_ahV0oFO7ITHW5_DXvIEc&e=


---

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
Karr Lab<http://www.karrlab.org/>
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...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160623/a47ddcb5/attachment-0001.htm>


More information about the testing-in-python mailing list