美文网首页
Python coverage 多进程

Python coverage 多进程

作者: DebugWorld | 来源:发表于2021-08-10 12:08 被阅读0次

新建 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

相关文章

网友评论

      本文标题:Python coverage 多进程

      本文链接:https://www.haomeiwen.com/subject/cumxbltx.html