Reputation: 556
I'm trying to figure out which lines of a Flask application are being run. I start Flask like this:
coverage run manage.py runserver
Output looks like this:
* Running on http://127.0.0.1:5000/
* Restarting with reloader
manage.py looks like this:
#!/usr/bin/env python
from flask.ext.script import Manager
from my_flask_app import app
manager = Manager(app)
if __name__ == '__main__':
manager.run()
I then access various parts of the application via HTTP.
When I look at the coverage HTML report, it says only the method definitions are covered, not the actual bodies of the methods.
I suspect it's because the methods are being executed by a subprocess which is not covered by coverage.py.
Any ideas?
Upvotes: 7
Views: 979
Reputation: 556
So it turns out that the problem is related to the 'reloader' message above. The coverage report is correct when I start Flask like this instead:
coverage run manage.py runserver -R
Output then only contains this:
* Running on http://127.0.0.1:5000/
This way it doesn't start up the server in a separate process, and coverage works great.
I found this solution thanks to this related Django question:
Why doesn't coverage.py properly measure Django's runserver command?
Upvotes: 6