3

Is it possible to measure python code coverage at runtime and view the results as they are generated? I tried using coverage but couldn't find an option that would help. My initial experiments show that the .coverage file isn't saved to until the end of the programs execution, meaning we can't view the results using 'coverage html' or 'coverage report'.

mattjegan
  • 2,724
  • 1
  • 26
  • 37
  • Do you not have a way to end your program cleanly? – Ned Batchelder Jul 18 '17 at 10:34
  • @NedBatchelder my use case is more for if I have a continuously running program like a web server and I wanted to see where my code hasn't been touched over a longer period of time – mattjegan Jul 18 '17 at 10:39
  • Maybe adding a way to end the server will be easier than using the coverage API in the code. – Ned Batchelder Jul 18 '17 at 14:54
  • @NedBatchelder perhaps during development that would be fine. I was thinking of a production environment where interrupting the server is probably not a good idea. Perhaps I'll make a PR into coverage at some point to add this. – mattjegan Jul 18 '17 at 21:17
  • If you want to take it on, drop me an email so we can discuss the design. – Ned Batchelder Jul 19 '17 at 01:56

1 Answers1

3

As of version 4.4, you can call coverage.save() and continue running. This means you have to use the coverage.py API inside your program rather than just using the command-line interface.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662