-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Missing lines of coverage when using redis #2912
Comments
I saw that python released a new version for python 3.11.5. I've tried everything again with this new version. I still see the same behavior in coverage, but I am now seeing an additional traceback from redis as the script closes. I thought it might be related to this line of missing coverage. I'm including it here: Exception ignored in: <function StreamWriter.del at 0x7fcd228adb20> |
redis 4.5.4 produces 100% coverage for me |
That's an interesting data point. I'll try moving my redis version back and see if I see the same. |
Any updates? The described problem still occurred in version 5.0.1. However, reverting back to 4.5.4 fixed the coverage issue. |
I believe this problem occurred after changes were made in this commit: c0833f6. These were introduced in version 4.5.5. Specifically, in line 531, where the So, I fixed this problem with a small patch, like so: import asyncio
class MyRedis(Redis):
async def execute_command(self, *args, **options):
return await asyncio.shield(
super().execute_command(*args, **options)
) I'm not sure if it's the ideal solution, but I added this patch solely for running tests and it successfully restored the correct coverage. |
Also seeing this behaviour using |
@eugenelandau I tried running my tests with this patch on |
I left an inquiry in the python coverage project (nedbat/coveragepy#1671). I'll repeat much of what I've said over there:
Describe the bug
When using asyncio with redis.asyncio, some lines that are definitely hit remain mysteriously uncovered, even when using a combination of different concurrency settings
To Reproduce
(I've tried various combinations of concurrency, but I most often leave it blank. I suspect it's not even appropriate for my application, though I'm not certain)
My minimal example (coverage_test.py):
I issue the coverage command with a bash script (coverage.sh) as follows:
The output of the script is:
And the coverage of the file looks like this:
I would expect the last print statement (which is executed, according to the output) to be marked green. I see there are some similar issues (most notably nedbat/coveragepy#1082 and nedbat/coveragepy#1598), but as I mentioned I haven't found a concurrency setting that mitigates this.
I was wondering if any of the maintainers of redis-py had any particular insights about what might cause this. I haven't been able to reproduce it so far with other libraries.
** Update **
I've been experimenting a bit with copying code from redis-py and asyncio to illustrate exactly where this problem happens. Here is my longer example:
This is what coverage looks like with the return (the one in the example above, called out in the comment, in the "stream_wait_for_data" function):
And without:
The text was updated successfully, but these errors were encountered: