python running coverage on never ending process

前端 未结 3 600
夕颜
夕颜 2021-02-05 09:01

I have a multi processed web server with processes that never end, I would like to check my code coverage on the whole project in a live environment (not only from tests).

3条回答
  •  独厮守ぢ
    2021-02-05 09:37

    You can use pyrasite directly, with the following two programs.

    # start.py
    import sys
    import coverage
    
    sys.cov = cov = coverage.coverage()
    cov.start()
    

    And this one

    # stop.py
    import sys
    
    sys.cov.stop()
    sys.cov.save()
    sys.cov.html_report()
    

    Another way to go would be to trace the program using lptrace even if it only prints calls it can be useful.

提交回复
热议问题