-
Notifications
You must be signed in to change notification settings - Fork 5
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
Full support for all async iterables/iterators as inputs and sources (even if they don't have an aclose()
)
#19
Full support for all async iterables/iterators as inputs and sources (even if they don't have an aclose()
)
#19
Conversation
Note: also applying to outputs so async_generator dep no longer needed.
Thanks for this. Haven't had time to do anything but a superficial look over the first couple of changes. The changes look ok so far. Hopefully I can get a moment to go through everything this weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going through this was quite a bit more challenging than I anticipated. I have never used test fixtures in pytest, so it was a lot to wrap my head around. Took a bit headscratching and some research to figure out. I wonder if maybe the same could be achieved with a simpler approach than creating a custom fixture function wrapper?
The other main comment is, that there seems to be some test code that is now redundant, because of the new fixtures, which could be removed. See the comments on the individual files.
I appreciate you putting in the time! To answer your question, the other approach would be to duplicate all of the tests to cover both cases separately. While that's "simpler" in some way, it's a maintainability trade-off because it's much less DRY, the risk being that when making a test update, one misses one of the two places. IMO maintainability and consistency should be the overriding concerns, but I'll of course defer to your wishes if you prefer the explicitly duplicated tests. |
Merged! Thanks! And sorry for the extremely long delay! I went to Texas for the eclipse for two weeks and just came back this weekend and before that, prep for travel and work took up all my time. |
Hehe, no worries. I was also in Texas (where I live) for the eclipse. Hadn't seen a cloud for three months prior. Suddenly overcast that day. |
In
_utils.py
, this branch providessafe_closing()
(only meant for Slurry's use, so no doc changes). It can be used in place of theasync_generator.aclosing()
context manager that was used frequently previously, with two differences that make it safer (and also type-checker friendly as it is correctly typed as supporting all these cases):aclose()
method, which is only somewhat unusual.Also provided is a
safe_aclose()
async function intended to be used anywhere an explicitaclose()
method call is desired, but with the benefit of item 2 above, so that it's safe to use without checking for the presence ofaclose()
.All of the input async gens that previously lived in
tests/fixtures.py
are now set up as actual pytest fixtures (intests/conftest.py
). This allows them to yield both "withaclose()
" and "withoutaclose()
" versions of themselves so that all existing tests that use them (with a small signature update) automatically generate tests for both cases (test count went from 43 to 76 to cover all these cases).As a result of using
safe_closing()
everywhere, theasync_generator
dependency is no longer needed, and has been removed.