Skip to content
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

[35] Support async/await fixtures #37

Merged

Conversation

altendky
Copy link
Member

@altendky altendky commented Sep 21, 2018

Redo of #36 but straight off of master

WIP for:

Redo of pytest-dev#35 but straight off of master
@altendky
Copy link
Member Author

Does not support yield in the async fixture yet. Though I'm just all around skeptical I've got this right anyways...

altendky added a commit to altendky/pytest-twisted that referenced this pull request Sep 21, 2018
@altendky
Copy link
Member Author

@schmir and @vtitor, any opinions on this? Concerns? One consideration that was suggested was to actually require an explicit mark of some sort for pytest-twisted to manage the async def instead of just consuming them all. I believe it was pytest-trio that was setup this way.

@altendky
Copy link
Member Author

altendky commented Sep 25, 2018

Also, pytest-asyncio pytest-trio (see below) requires async fixtures to be function scoped. I believe my present implementation should have that restriction as well (both in code and documentation).

Copy link

@meejah meejah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:LGTM:
(caveat: I've just read the code, not tried it myself yet..)

pytest_twisted.py Outdated Show resolved Hide resolved
testing/test_basic.py Show resolved Hide resolved
@meejah
Copy link

meejah commented Oct 29, 2018

@altendky Hmm, why does asyncio insist on function-scoped async fixtures...?

@altendky
Copy link
Member Author

@meejah, my apologies. It was Trio that only has function scoped fixtures. They have no global reactor and start a new one (so to speak) for each test. It seems that asyncio does support all fixture scopes.

https://github.com/pytest-dev/pytest-asyncio#async-fixtures

@altendky
Copy link
Member Author

It doesn't seem like async fixture scope needs to be be restricted to just 'function'. Perhaps shifting to using pyest_fixture_setup() would be part of eliminating the restriction.

@meejah
Copy link

meejah commented Oct 29, 2018

Okay, yeah from my perspective at least having all scopes would be best :)

I wonder if this should ape asyncio with a reactor fixture, too..? I certainly have made reactor fixtures for several Twisted + pytest things .. but I don't know how/if these would work with some pytest-twisted-provided reactor fixture. e.g. one reason I had my own reactor fixture was to parametrize it on two different reactors (or, e.g., to ensure a particular reactor was being selected).

I guess I'm asking: if pytest-twisted provided a reactor fixture, can a conftest.py that I write override that?

@altendky
Copy link
Member Author

As I recall, pytest-twisted tries to setup the global reactor asap and leave it running throughout. I don't know what it would take to move away from the global reactor.

#16 (comment)

@meejah
Copy link

meejah commented Oct 29, 2018

As I recall, pytest-twisted tries to setup the global reactor asap and leave it running throughout. I don't know what it would take to move away from the global reactor.

Ah, okay, ignore that thought for this PR, then.

@altendky altendky changed the title [35] [WIP] Support async/await fixtures [35] Support async/await fixtures Sep 26, 2019
@altendky altendky merged commit c4691e5 into pytest-dev:master Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants