-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
Wrong coverage when using SQLAlchemy+asyncpg+strawberry-graphql #1216
Comments
Thanks for the reproducible case :) I see the same results you do, and I don't understand them. But if I replace |
Thanks for the reply! I've tried the I've also tried reproducting this with only strawberry or only SQLAlchemy, to no avail. They both fiddle with Python internals, hard for me to say what exactly might cause the problem. |
I've updated the gist and simplified the example code even more - it's enough to call |
@nedbat I've decided to look a bit into this again and found that making the following change in the Python tracer fixes this specific issue, but I am not sure why. The only change is the addition of the line which "syncs" # Original
...
elif event == 'line':
# Record an executed line.
if self.cur_file_data is not None:
lineno = frame.f_lineno
if self.trace_arcs:
self.cur_file_data.add((self.last_line, lineno))
else:
self.cur_file_data.add(lineno)
self.last_line = lineno
... # Modified
...
elif event == 'line':
# Record an executed line.
self. cur_file_data = self.data.get(frame.f_code.co_filename, None) # This is the new line.
if self.cur_file_data is not None:
lineno = frame.f_lineno
if self.trace_arcs:
self.cur_file_data.add((self.last_line, lineno))
else:
self.cur_file_data.add(lineno)
self.last_line = lineno
... Seems like only three tests fail following this change. I think that maybe one of the libraries leads to |
@Apakottur I stumbled on this as well. SQLAlchemy uses greenlet under the asyncio hood. You need to instruct coverage to take this into account, see #841 (comment) |
@klaasjanelzinga Super nice find! This seems so obvious in retrospect, I just never got to do a bit more trace investigation. |
Hey + 1 to Apakottur. If you're using FastAPI, make sure to include thread as well. Coverage has a hard time keeping track of both without explicitly declaring. https://stackoverflow.com/questions/74305054/pytest-cov-does-not-cover-all-lines-when-using-sqlalchemy-async-session For a pyproject definition: [tool.coverage.run] |
Describe the bug
We are using the (awesome!!) coverage script in our projects and recently we've been getting some incorrect results.
The coverage script shows some code as uncovered even though it's being executed.
To Reproduce
The problem only seems to occur when multiple complex libraries are used together. Here's a minimal example that reproduces the problem:
https://gist.github.com/Apakottur/cc0b0ae6bd982dd1c2f48880ce8d9749
We use docker to fix the package versions, so to run the example one needs
docker
anddocker-compose
installed.With all these files in the same directory, running
docker-compose up --build test
gives us:Which is clearly contradictory, as lines 29-30 contain the printout
This is not covered
, which is printed.How would we go and debug this further? Is there a way to step through the coverage script and see why it's not considering these lines?
The text was updated successfully, but these errors were encountered: