mercredi 21 janvier 2015

How to delete persisting objects in py.test?

The following are my tests which I run using py.test:



def test_config1():
_config_file1 = "some_file_1.cfg"
sim1 = Simulator(_config_file1)
sim1.run()
assert sim1.a == 4

def test_config2():
_config_file2 = "some_file_2.cfg"
sim2 = Simulator(_config_file2)
sim2.run()
assert sim2.a == 14


sim1 creates some objects which persist in memory even when sim1 goes out of scope and sim2's simulation has begun. How do I ensure that those objects get deleted before sim2 starts. I have tried putting the tests in different files but I am assuming py.test runs them all in the same process because of which those objects created by sim1 persist and cause sim2 to provide wrong results. If the order of the tests is reversed sim2 runs fine but sim1 doesn't.


One way would be do write a destructor of sim1 that deletes all those objects it creates. Is there any other way to delete persisting objects in py.test?


Aucun commentaire:

Enregistrer un commentaire