新建 a.py 文件
from multiprocessing import Process
def job(s):
print(s, os.getpid())
def test():
print('it is test', os.getpid())
def main():
test()
p1 = Process(target=job, args=('Hello', ))
p2 = Process(target=job, args=('World', ))
p1.start()
p2.start()
p1.join()
p2.join()
新建 b.py
import a
import unittest
class TestMain(unittest.TestCase):
def test_job(self):
a.main()
if __name__ == '__main__':
unittest.main()
新建 setup.cfg
[run]
concurrency = multiprocessing #在这个地方指定你的多进程实现方式
[report]
# Regexes for lines to exclude from consideration
exclude_lines = # Have to re-enable the standard pragma pragma: no cover # Don't complain about missing debug-only code: def __repr__ if self\.debug # Don't complain if tests don't hit defensive assertion code: raise AssertionError raise NotImplementedError # Don't complain if non-runnable code isn't run: if 0: if __name__ == .__main__.:
[html]
directory = coverage_html_report
运行
coverage run --rcfile=setup.cfg --concurrency=multiprocessing b.py
coverage combine # 聚合
coverage report -m
coverage html