Measuring code coverage when using Selenium and pytest

20 views
Skip to first unread message

Shaheed Haque

unread,
Apr 13, 2019, 11:35:17 AM4/13/19
to Django users
Hi,

I'd like to get coverage.py running against my code base. The code consists of standard Django, some Celery code, some django-viewflow code and some Celery-and-django-viewflow code [1]. The main problem I see is that if I say "coverage -p manage.py runserver ...", I need a way for the server to exit in a way which allows coverage to end the run and write its output. For now, I achieve this by hacking in a specific view and arranging to call "_thread.interrupt_main()" at an appropriate time. This indeed causes a coverage output file to be written.

Unfortunately, the recorded results only show the static reading of the code files, so that class and function definitions are read, but no function body lines show up as covered. I suspected this might have something to do with spawned processes, so I have tried using "runserver --noreload" to avoid the second process, but to no avail.

Why is the normally executed code path not shown as executed? AFAIK, there should be no multi-processing or similar in play...am I mistaken in that regard?

Thanks, Shaheed

P.S. In separate attempts, I tried all the relevant techniques in this StackOverflow discussion such as using the coverage.py API in manage.py.

[1] I realise that:
  • Celery and coverage.py are not comfortable bedfellows (I believe this is due to Celery using its own billard package, rather then generic multiprocessing, which coverage.py apparently knows about).
  • There are standard recipies for getting coverage.py running when using "manage.py test", but the tests in my current project are not run this way; instead, pytest is used to invoke the tests, most of which use Selenium.
Reply all
Reply to author
Forward
0 new messages