-
Notifications
You must be signed in to change notification settings - Fork 310
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
Add missing sessions test #156
Conversation
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.
@Zsailer - thanks for getting this in so quickly. I just had a question and a comment.
assert got == new_session | ||
|
||
# Need to find a better solution to this. | ||
await session_client.cleanup() |
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.
Can we add these cleanup calls to the fixture, after the yield and prior to the dir removal?
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.
Yeah, I had tried to get this to work, but async-ness of this call makes it challenging. I couldn’t find a way to both yield in the session client fixture and use this asynchronous cleanup method. Do you how to do this?
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.
Yeah, I see what you mean. I just tried a few things to no avail. There are ways to create async fixtures but I'm not having much luck. Let's revisit since this is more of a test impl issue.
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.
I'm currently having success with this (using pytest.yield_fixture and run_sync). File attached below ...
def run_sync(coro_method):
return asyncio.get_event_loop().run_until_complete(coro_method)
@pytest.yield_fixture
def session_client(root_dir, fetch):
subdir = root_dir.joinpath('foo')
subdir.mkdir()
# Write a notebook to subdir.
nb = new_notebook()
nb_str = writes(nb, version=4)
nbpath = subdir.joinpath('nb1.ipynb')
nbpath.write_text(nb_str, encoding='utf-8')
# Yield a session client
client = SessionClient(fetch)
yield client
# Invoke async method on separate loop
run_sync(client.cleanup())
# Remove subdir
shutil.rmtree(str(subdir), ignore_errors=True)
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.
Warning - I'm not convinced this will work on 3.5 and I'd prefer to understand things better (like why does yield_fixture change things).
Test on my mac and tests passed. We have 1 more warning. LGTM - I guess we can merge when Zach will have pushed the change he was not able during his fly. We can also come back on the async fixture later. |
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.
OK. Let's circle back regarding the session teardown issue once 0.2 is done.
Thanks, @kevin-bates! |
@kevin-bates and @echarles Here are the missing sessions tests left out of #152.