How to measure test coverage of app on python if application and tests in different projects

Viewed 304

I want to measure coverage in my project by integration tests (integration of several microservices). Applications - python, tests - pytest.

I know about pytest-cov, but the problem is that my application and tests start in different docker containers. And all interaction between app and tests is carried out through http. So tests know nothing about applications code and vice versa the same.

I know that in C/С# it is possible to make special build (instrumental build - or something like this (the name may be wrong :-))). The main idea it is that after work, application generate some report with coverage and you can check it.

Is there something similar for python? Or may be some another way?

1 Answers

However you start your application under test, you can start it with coverage.py instead. If you normally use python my_app.py, use coverage run my_app.py instead. When the app finishes, you will have coverage data for the application.

Coverage.py is the coverage measurement tool that pytest-cov coordinates. You will get the same measurement.

Related