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

aioloop-proxy usage draft #312

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Work on
  • Loading branch information
asvetlov committed Jan 24, 2022
commit 8e5ac2ac16d17318486bcb9c8fd4166500b38137
13 changes: 10 additions & 3 deletions pytest_asyncio/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def install(
) -> None:
node = request.node
print("\n+++++++++", id(node))
if hasattr(request, "param"):
print("@@@@@@@@@", request.param)
# if hasattr(request, "param"):
# print("@@@@@@@@@", request.param)
runner = getattr(node, "_asyncio_runner", None)
if runner is None:
runner = cls(node, loop)
Expand All @@ -32,7 +32,14 @@ def install(
# parametrized non-function scope loop was recalculated
# with other params or precessors
runner._set_loop(loop)
request.addfinalizer(runner._uninstall)

@classmethod
def uninstall(cls, request: pytest.FixtureRequest) -> None:
node = request.node
print("#########", id(node), type(node))
runner = getattr(node, "_asyncio_runner", None)
assert runner is not None
runner._uninstall

@classmethod
def get(cls, node: pytest.Item) -> "Runner":
Expand Down
3 changes: 3 additions & 0 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,16 @@ def pytest_fixture_post_finalizer(fixturedef: FixtureDef, request: SubRequest) -
new_loop = policy.new_event_loop() # Replace existing event loop
# Ensure subsequent calls to get_event_loop() succeed
policy.set_event_loop(new_loop)
Runner.uninstall(request)


@pytest.hookimpl(hookwrapper=True)
def pytest_fixture_setup(
fixturedef: FixtureDef, request: SubRequest
) -> Optional[object]:
"""Adjust the event loop policy when an event loop is produced."""
if hasattr(request, "param"):
print("@@@@@@@@@", fixturedef.argname, request.param)
if fixturedef.argname == "event_loop":
# a marker for future runners lookup
# The lookup doesn't go deeper than a node with this marker set.
Expand Down