Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage warning: "No source for code: '/my/local/folder/_run_response_middleware'. (couldnt-parse)" #2345

Closed
NonStatic2014 opened this issue Dec 29, 2021 · 8 comments

Comments

@NonStatic2014
Copy link

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:

No source for code: '/my/local/folder/_run_request_middleware'.

with coverage xml -i there are more warnings:

/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/_run_request_middleware': No source for code: '/my/local/folder/_run_request_middleware'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/_run_response_middleware': No source for code: '/my/local/folder/_run_response_middleware'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/connection_task': No source for code: '/my/local/folder/connection_task'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/handle_exception': No source for code: '/my/local/folder/handle_exception'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/handle_request': No source for code: '/my/local/folder/handle_request'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/http1_request_header': No source for code: '/my/local/folder/http1_request_header'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/http1_response_header': No source for code: '/my/local/folder/http1_response_header'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/read': No source for code: '/my/local/folder/read'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
/my/local/virtualenv/lib/python3.8/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '/my/local/folder/send': No source for code: '/my/local/folder/send'. (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")
Wrote XML report to coverage.xml

Code snippet

In blueprint.py

my_bp = Blueprint("my_blueprint")

Create app in a different file:

my_app = Sanic(name, load_env=False, log_config=LOG_SETTINGS)
my_app.blueprint(my_bp)
my_app.register_middleware( ..... )

Expected behavior
No warning or error while generating code coverage report, like using sanic 21.6.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Version 21.9 and 21.12, not repro on 21.6
  • Python: 3.8

Additional context

$ pip freeze | grep "sanic\|coverage\|pytest"
coverage==6.2
pytest==6.2.5
pytest-asyncio==0.15.1
sanic==21.9.3
sanic-routing==0.7.2
sanic-testing==0.8.2
@NonStatic2014 NonStatic2014 changed the title Code coverage warning: "No source for code: '/my/local/path/_run_response_middleware'. (couldnt-parse)" Code coverage warning: "No source for code: '/my/local/folder/_run_response_middleware'. (couldnt-parse)" Dec 29, 2021
@ahopkins
Copy link
Member

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.

@NonStatic2014
Copy link
Author

I'm trying to run coverage on my server code but hit error/warning on sanic code. this is the place actually confused me.

@NonStatic2014
Copy link
Author

NonStatic2014 commented Dec 29, 2021

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.

@ahopkins
Copy link
Member

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.

@ahopkins
Copy link
Member

I am closing this now as the issue is not really related to Sanic. Feel free to continue the conversation.

@rbm-radius
Copy link

@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.

@ahopkins
Copy link
Member

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.

@rbm-radius
Copy link

@ahopkins done! Let me know if more examples are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants