I am writing integration tests for a project in which I am making HTTP calls and testing whether they were successful or not.
Since I am not importing any module and not calling functions directly coverage.py report for this is 0%.
I want to know how can I generate coverage report for such integration HTTP request tests?
The recipe is pretty much this:
Example:
backend
Imagine you have a dummy backend server that responds with a "Hello World" page on GET requests:
test
A simple test that makes an HTTP request and verifies the response contains "Hello World":
Recipe
cov
is the fixture provided bypytest-cov
(docs).Running the test adds the coverage of
backend.py
to the overall coverage, although onlytests
selected: