Skip to content

Prevent double wrapping of inherited Hypothesis tests #239

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

Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Changelog
~~~~~~~~~~~~~~~~~~~
- `pytest-asyncio` no longer alters existing event loop policies. `#168 <https://github.com/pytest-dev/pytest-asyncio/issues/168>`_, `#188 <https://github.com/pytest-dev/pytest-asyncio/issues/168>`_
- Drop support for Python 3.6
- Fixed an issue when pytest-asyncio was used in combination with `flaky` or inherited asynchronous Hypothesis tests. `#178 <https://github.com/pytest-dev/pytest-asyncio/issues/178>`_ `#231 <https://github.com/pytest-dev/pytest-asyncio/issues/231>`_
- Added `flaky <https://pypi.org/project/flaky/>`_ to test dependencies

0.16.0 (2021-10-16)
~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 4 additions & 3 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ async def setup():
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
"""
Run asyncio marked test functions in an event loop instead of a normal
function call.
Pytest hook called before a test case is run.

Wraps marked tests in a synchronous function where the wrapped test coroutine is executed in an event loop.
"""
if "asyncio" in pyfuncitem.keywords:
if getattr(pyfuncitem.obj, "is_hypothesis_test", False):
Expand All @@ -176,7 +177,7 @@ def wrap_in_sync(func, _loop):
# if the function is already wrapped, we rewrap using the original one
# not using __wrapped__ because the original function may already be
# a wrapped one
if hasattr(func, '_raw_test_func'):
if hasattr(func, "_raw_test_func"):
func = func._raw_test_func

@functools.wraps(func)
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/hypothesis/test_inherited_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import hypothesis.strategies as st
from hypothesis import given
import pytest


class BaseClass:
@pytest.mark.asyncio
@given(value=st.integers())
async def test_hypothesis(self, value: int) -> None:
assert True


class TestOne(BaseClass):
"""During the first execution the Hypothesis test is wrapped in a synchronous function."""

pass


class TestTwo(BaseClass):
"""Execute the test a second time to ensure that the test receives a fresh event loop."""

pass