Skip to content

Commit

Permalink
simplify host
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Jul 29, 2020
1 parent 03742c3 commit a658224
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions qtrio/_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,18 @@ def host(test_function: typing.Callable[..., typing.Awaitable[None]]):
test_function: The pytest function to be tested.
"""

@pytest.mark.usefixtures("qapp", "qtbot")
@pytest.mark.usefixtures("qapp")
@functools.wraps(test_function)
def wrapper(*args, **kwargs):
request = kwargs["request"]

qapp = request.getfixturevalue("qapp")
qtbot = request.getfixturevalue("qtbot")

test_outcomes_sentinel = qtrio.Outcomes(
qt=outcome.Value(0), trio=outcome.Value(29),
)
test_outcomes = test_outcomes_sentinel

def done_callback(outcomes):
nonlocal test_outcomes
test_outcomes = outcomes

runner = qtrio._core.Runner(
application=qapp,
done_callback=done_callback,
quit_application=False,
timeout=timeout,
)

runner.run(
functools.partial(test_function, **kwargs),
*args,
execute_application=False,
)

# TODO: probably increases runtime of fast tests a lot due to polling
qtbot.wait_until(
lambda: test_outcomes is not test_outcomes_sentinel, timeout=3.14e8
)

runner = qtrio._core.Runner(application=qapp, timeout=timeout)

async_fn = functools.partial(test_function, *args, **kwargs)
test_outcomes = runner.run(async_fn=async_fn)

test_outcomes.unwrap()

return wrapper

0 comments on commit a658224

Please sign in to comment.