I have code that uses multiprocessing.Pool to fork workers and execute a task in parallel. I am trying to find the right way to run unit tests of this code.
Note. I am not trying to test serial code test cases in parallel, which I know as nose-enabled packages.
If I write a test function that checks parallel code and try to run tests with the nose with:, the nosetests tests/test_function.py
non-parallel test runs correctly, but the parallel tests fail when the multiprocessor tries to use fork because main is not imported
File "C:\python-2.7.10.amd64\lib\multiprocessing\forking.py", line 488, in prepare
assert main_name not in sys.modules, main_name
AssertionError: __main__
assert main_name not in sys.modules, main_name
AssertionError: _assert main_name not in sys.modules, main_name
_main__AssertionError
: __main__
It just repeats until I finish the task. I can run the tests successfully if I change tests/test_function.py
to include:
if __name__ == '__main__':
import nose
nose.main()
and then do with python tests\test_function.py
So, what is the “right” way to do this, which will integrate with the unit test package (shouldn't be the nose)?
Environ: Python 2.7.10 amd64 for Windows 7 64-bit
source
share