Closed
Description
Currently, it is not possible to use the py.test
command to run tests that use the multiprocessing
module with a start-method other than fork. This is because the py.test
script generated by setuptools does not include a if __name__ == '__main__'
guard:
$ cat /usr/bin/py.test-3
#! /usr/bin/python3
import sys
from pkg_resources import load_entry_point
sys.exit(load_entry_point('pytest==2.6.3', 'console_scripts', 'py.test')())
This means that as soon as a test tries to spawn a new process, this process starts executing the test-suite itself (the -s
option is necessary to see the output of the second process):
$ py.test-3 test_mp.py -s
============================================== test session starts ==============================================
platform linux -- Python 3.4.2 -- py-1.4.25 -- pytest-2.6.3
collected 1 items
test_mp.py ============================================== test session starts ==============================================
platform linux -- Python 3.4.2 -- py-1.4.25 -- pytest-2.6.3
collected 1 items
test_mp.py F
[...]
This is easily rectified by using a custom py.test
command:
$ cat run_test.py
#!/usr/bin/python3
import pytest
import sys
if __name__ == '__main__':
sys.exit(pytest.main([__file__] + sys.argv[1:]))
$ python3 run_test.py test_mp.py -s
============================================== test session starts ==============================================
platform linux -- Python 3.4.2 -- py-1.4.25 -- pytest-2.6.3
collected 1 items
test_mp.py hello
.
=========================================== 1 passed in 0.11 seconds ============================================
But it would be much nicer if the standard py.test
command could be used.
Metadata
Metadata
Assignees
Labels
No labels