coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

Question: How to get the coverage data for each incoming request on my web server.

Open AkashKumar7902 opened this issue 1 year ago • 2 comments

consider a sample python application (https://github.com/keploy/samples-python/tree/main/django-postgres), I want to get the coverage data for each request coming to my server.

I am aware of dynamic-context, but that it is a different thing, it provides only one option (test_function).

AkashKumar7902 avatar Feb 05 '24 06:02 AkashKumar7902

You might need to try using the Coverage API, using start() and stop() around the request, and then examining the data each time. When you say "each request" I don't know if you mean every single request being made, or each different kind of request?

nedbat avatar Feb 05 '24 12:02 nedbat

Hey @nedbat thanks for the response.

You might need to try using the Coverage API, using start() and stop() around the request, and then examining the data each time.

I am not sure how that can be done at the server side. I would be grateful for any insights.

Little background here: I want to develop a module that does this for any python server out there.

When you say "each request" I don't know if you mean every single request being made, or each different kind of request?

I meant every single API request being made to the server. In the context of sample app I linked in the issue description, it would mean any request which comes to the five endpoints.

AkashKumar7902 avatar Feb 05 '24 12:02 AkashKumar7902

solved this using middleware

AkashKumar7902 avatar Jul 10 '24 09:07 AkashKumar7902