vendredi 7 juillet 2017

Python: How to tests a program that uses fork?

I am writing a program that uses several instances of the same code in production. Instances then communicate over network, but that is irrelevant here.

During development, I fork the initial process multiple times to get a complete setup of instances, which is very convenient.

However, trying to write integration tests on this gives me problems: The test framework (unittest/nosetests/py.test) is of course also forked, so that I end up with multiple copies test framework, providing garbled results.

Ideally, I'd like to fork off said instances of the program on test start, with the main process just supervising the child processes for errors as well as running the test suite. The tests in the test suite will query the instances through an API.

To achieve this, I'd need to "unload" or stop the test frameworks from the child processes. How can I do this?

I could fix this by invoking the test suite only after forking off the children, but I need to re-start all children for every test.

Aucun commentaire:

Enregistrer un commentaire