I have Web Application where the source code is in Python. All the regression tests are in Java. I wish to perform Code Coverage for the application. Please suggest a code coverage tool to instrument the python application .I should then be able to execute Java selenium tests over it and fetch coverage report

  • What type of coverage are you interested in? E.g., if you want to investigate the endpoints you are hitting and the request trace, something like OpenTracing or OpenCensus may help, For other types of coverage (see here sqa.stackexchange.com/a/44995/12740), other tools may be more appropriated. Jul 30, 2020 at 14:24
  • Basically, I wanted to get the code coverage% of the application's source code against the selenium automation tests . For example - X% of code is covered by "Y" number of tests. This is to ensure how much % of code is hit by automation tests
    – SanKarun
    Jul 30, 2020 at 21:05

1 Answer 1


You should install coverage package. I have both python2 and python3 on my computer so I'll show you how to deal with my case and python 3.

So say you have the following program:

g = input("Enter your age: ") 

if int(g) < 15:
  print("You are a child")
  print("You are not a child")

  1. Install coverage tool: pip3 install coverage
  2. Use coverage tool to run your application under test: coverage3 run undertest.py
  3. Perform your tests (e.g. input 5 when prompted - in your case you would run your Selenium test suite)
  4. Where you have run your app under test you should now see .coverage file.
  5. Run coverage3 html. You should now have html report generated at the same folder.


enter image description here

Disclaimer: Since I have both 2 and 3 versions of python at the same time I need to use commands which explicitly use version 3. I am not sure what would be the behavior if you have only version 3. So if those commands won't work for you, try to omit 3 (e.g. pip install coverage or coverage run blah-blah-blah)

  • Thanks for the explanation , Alexey. So, once my web application is run using coverage command, as mentioned in 3rd step, java-selenium tests can be executed against the application. Is my understanding right ? Also , when would ".coverage" file get generated? Do we have ways to manually stop the coverage ? Please clarify.
    – SanKarun
    Aug 2, 2020 at 19:57
  • Yes. You can run your selenium tests or even manual tests. coverage file is being altered all the way your tests are running. Basically it is a SQLite database. You can stop your application and your coverage will be stopped.
    – Alexey R.
    Aug 2, 2020 at 20:13
  • This helps ! Thanks Alexey. Will implement using coverage.py
    – SanKarun
    Aug 3, 2020 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.