Closed NonStatic2014 closed 2 years ago
Why are you running coverage for Sanic?
You will not get coverage for these functions because they are rewritten at startup time based upon your application's code.
I'm trying to run coverage on my server code but hit error/warning on sanic code. this is the place actually confused me.
blueprint.py
and other python code of my server is in the folder /my/local/folder/
. I don't expect any coverage number from sanic.
And can you explain a little more about this?
they are rewritten at startup time based upon your application's code.
However you are running coverage, it is including the portions of Sanic that are imported into your application. What version of coverage
are you using? See this article.
And can you explain a little more about this?
Sure! This is an important feature of Sanic going forward. I am myself working out this whole coverage issue because it is a PITA. We handle it currently by simply ignoring those methods. Not ideal.
What is happening is that when you first load Sanic, it does some self inspection of the types of handlers that you have setup. Currently it is looking for a few specific items: (1) what signals are implemented by the application; and (2) what content_type
is each route handler likely to produce. The first item is used to trim out unneeded code from executing, thus making Sanic more efficient. The second is used to determine how to handle error formatting in an appropriate manner.
In the coming year, there likely will be some more of these introspection style optimizations.
I am closing this now as the issue is not really related to Sanic. Feel free to continue the conversation.
@ahopkins respectfully I'd like to reopen this--it is a Sanic issue because of the generated code, which causes confusion with other tools looking for persistent modules. No other package I've used out of ~250 in my current app does this.
Feel free to create a new issue and reference this. I would ask @rbm-radius if you can provide a use case and a simple repeatable example of how/where this is causing problems.
@ahopkins done! Let me know if more examples are required.
Describe the bug After upgrade sanic from 21.6 to 21.9, coverage, we noticed when run
coverage xml
, there is an error like below:with
coverage xml -i
there are more warnings:Code snippet
In blueprint.py
Create app in a different file:
Expected behavior No warning or error while generating code coverage report, like using sanic 21.6.
Environment (please complete the following information):
Additional context