Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Jenkins code coverage work?

Tags:

python

jenkins

I am using Jenkins to build and monitor the testing for my application.

I have such a piece of python code:

def register_os_handler():
    def handler(signal, frm):
        raise SystemExit()
    signal(SIGHUP, handler)

In my test, I create a subprocess, and send it a SIGHUP signal and it quits as expected, which means it reaches the line of raise SystemExit().

When I submit it to Jenkins, all tests passed, but it says the line raise SystemExit() is not covered.

I feel curious that why that line was indeed reached, but still Jenkins complains?

  1. How does the Jenkins' coverage report work?

  2. If a process (even if it is a subprocess) quits, it cannot detect the line or take the line into account?

  3. How to get around this?

like image 673
Jackson Tale Avatar asked May 20 '26 03:05

Jackson Tale


1 Answers

I believe Jenkins uses coverage.py. If you want to compute coverage for subprocess, you need a little hack, which is described here:

http://nedbatchelder.com/code/coverage/subprocess.html

like image 196
zefciu Avatar answered May 21 '26 17:05

zefciu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!