Skip to content

Commit c8981ba

Browse files
committed
refactor: Extracted function that prepares execution of async Hypothesis tests for improved readability.
Signed-off-by: Michael Seifert <[email protected]>
1 parent f219c52 commit c8981ba

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pytest_asyncio/plugin.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,24 @@ def pytest_pyfunc_call(pyfuncitem):
158158
"""
159159
if "asyncio" in pyfuncitem.keywords:
160160
if getattr(pyfuncitem.obj, "is_hypothesis_test", False):
161-
hypothesis_inner_test = getattr(
162-
pyfuncitem.obj.hypothesis.inner_test,
163-
"original_test_function",
164-
pyfuncitem.obj.hypothesis.inner_test,
165-
)
166-
synchronous_test_function = wrap_in_sync(
167-
hypothesis_inner_test,
168-
_loop=pyfuncitem.funcargs["event_loop"],
169-
)
170-
pyfuncitem.obj.hypothesis.inner_test = synchronous_test_function
161+
_wrap_hypothesis_test(pyfuncitem)
171162
else:
172163
pyfuncitem.obj = wrap_in_sync(
173164
pyfuncitem.obj, _loop=pyfuncitem.funcargs["event_loop"]
174165
)
175166
yield
176167

177168

169+
def _wrap_hypothesis_test(pyfuncitem):
170+
inner_test = pyfuncitem.obj.hypothesis.inner_test
171+
original_test = getattr(inner_test, "original_test_function", inner_test)
172+
synchronous_test_function = wrap_in_sync(
173+
original_test,
174+
_loop=pyfuncitem.funcargs["event_loop"],
175+
)
176+
pyfuncitem.obj.hypothesis.inner_test = synchronous_test_function
177+
178+
178179
def wrap_in_sync(func, _loop):
179180
"""Return a sync wrapper around an async function executing it in the
180181
current event loop."""

0 commit comments

Comments
 (0)