-
Notifications
You must be signed in to change notification settings - Fork 70
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
chore: introduce asyncio mode #184
Conversation
3eec557
to
ffbd3e9
Compare
Just a recap of this issue and why we don't proceed: Ideally we can have sync and async in the same repository and based on if a test file is marked as sync, it uses the sync fixtures or its async and it uses the async Playwright fixtures. So far I didn't find a great way of doing that Pytest wise. |
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.
There is pytest_asyncio.is_async_test
which may be helpful to you: https://github.com/pytest-dev/pytest-asyncio/blob/v0.23.3/pytest_asyncio/plugin.py#L988-L990
|
||
|
||
def pytest_configure(config: pytest.Config) -> None: | ||
if (config.getini("playwright_pytest_asyncio") is None and config.pluginmanager.hasplugin("asyncio")) or config.getini("playwright_pytest_asyncio"): |
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.
To share, I have seen others using AnyIO for async
testing: https://anyio.readthedocs.io/en/1.4.0/testing.html
It might be good to account for other async
plugins that can trigger registration of PytestPlaywrightAsyncio
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.
Re #184 (review):
We'll do it on a global level for now since it seems simpler. Sync and Async fixtures seem to be significant different, hence deciding this on a test-level won't work. Browser and Playwright instance in the Pytest plugin are e.g. on session scope, so that would also end up in clashes / conflicts.
Re #184 (comment):
We'll do it opt-in rather than auto-detect for now, since the chance of false activations seems to high and we'd probably break existing users.
Appreciate your input!
ee8b47a
to
330b27c
Compare
330b27c
to
7b3872e
Compare
Here are instructions on how to use it / provide feedback: #74 (comment) |
Abstract: This PR allows using Pytest with our async/await bindings and not only our sync bindings compared to before.
Current implementation: By default it will use the sync fixtures. In order to opt-in for async fixtures, set this setting in the
pytest.ini
:Internal: All the tests got mirrored, changed to the asyncio way of doing this except two UnitTest tests, which are not supported with pytest-asyncio see here.
Pytest plugin reference: https://docs.pytest.org/en/8.1.x/how-to/writing_hook_functions.html#optionally-using-hooks-from-3rd-party-plugins
Relates #74
Previously when discussing it with the team we were interested in having sync/async tests mixed inside a folder or a file. Having it inside a file is not possible because async fixtures are significantly different compared to normal fixtures. Since the fixtures instances are shared inside the file, they need to be equal, either one or the other.
Inside a folder isn't possible with this approach, since test files are getting loaded later on - it might be possible with different hooks / implementation but not sure if it is worth it.