Skip to content

Commit 4178406

Browse files
committed
refactor: Make PytestAsyncioFunction.loop_scope protected.
1 parent 5560526 commit 4178406

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pytest_asyncio/plugin.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,30 +442,15 @@ def _can_substitute(item: Function) -> bool:
442442
"""Returns whether the specified function can be replaced by this class"""
443443
raise NotImplementedError()
444444

445-
@functools.cached_property
446-
def loop_scope(self) -> _ScopeName:
447-
"""
448-
Return the scope of the asyncio event loop this item is run in.
449-
450-
The effective scope is determined lazily. It is identical to to the
451-
`loop_scope` value of the closest `asyncio` pytest marker. If no such
452-
marker is present, the the loop scope is determined by the configuration
453-
value of `asyncio_default_test_loop_scope`, instead.
454-
"""
455-
marker = self.get_closest_marker("asyncio")
456-
assert marker is not None
457-
default_loop_scope = _get_default_test_loop_scope(self.config)
458-
return _get_marked_loop_scope(marker, default_loop_scope)
459-
460445
def setup(self) -> None:
461446
fixturenames = self.fixturenames
462-
runner_fixture_id = f"_{self.loop_scope}_scoped_runner"
447+
runner_fixture_id = f"_{self._loop_scope}_scoped_runner"
463448
if runner_fixture_id not in fixturenames:
464449
fixturenames.append(runner_fixture_id)
465450
return super().setup()
466451

467452
def runtest(self) -> None:
468-
runner_fixture_id = f"_{self.loop_scope}_scoped_runner"
453+
runner_fixture_id = f"_{self._loop_scope}_scoped_runner"
469454
runner = self._request.getfixturevalue(runner_fixture_id)
470455
context = contextvars.copy_context()
471456
synchronized_obj = _synchronize_coroutine(
@@ -475,6 +460,21 @@ def runtest(self) -> None:
475460
c.setattr(*self._synchronization_target_attr, synchronized_obj)
476461
super().runtest()
477462

463+
@functools.cached_property
464+
def _loop_scope(self) -> _ScopeName:
465+
"""
466+
Return the scope of the asyncio event loop this item is run in.
467+
468+
The effective scope is determined lazily. It is identical to to the
469+
`loop_scope` value of the closest `asyncio` pytest marker. If no such
470+
marker is present, the the loop scope is determined by the configuration
471+
value of `asyncio_default_test_loop_scope`, instead.
472+
"""
473+
marker = self.get_closest_marker("asyncio")
474+
assert marker is not None
475+
default_loop_scope = _get_default_test_loop_scope(self.config)
476+
return _get_marked_loop_scope(marker, default_loop_scope)
477+
478478
@property
479479
def _synchronization_target_attr(self) -> tuple[object, str]:
480480
"""

0 commit comments

Comments
 (0)