taverntesting / tavern

A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax
https://taverntesting.github.io/
MIT License
1.02k stars 193 forks source link

How to measure coverage for tavern tests? #890

Closed jykae closed 9 months ago

jykae commented 10 months ago

First of all, thank you for creating such nice API testing framework on top of pytest

Would like to be able to measure coverage for Fastapi application, I am trying to use tavern-fastapi plugin if using TestClient would solve the issue for measuring coverage, however getting error https://github.com/zaghaghi/tavern-fastapi/issues/2

Is there anyway to get tavern tests executed in a way that pytest-cov would give right measures for Fastapi tests written in tavern? Maybe even something that would not require using specific client 🤔

michaelboulton commented 9 months ago

because Tavern isn't running in the same process as your Python server, If you want to do that you'll need to run your server under 'coverage' like:

$ coverage run path/to/server.py

Run tavern tests against that running server, then do 'coverage report' (or however you are using that data) to get the coverage output