diff --git a/README.rst b/README.rst index f2d64987..4d264ce2 100644 --- a/README.rst +++ b/README.rst @@ -175,6 +175,8 @@ Changelog ~~~~~~~~~~~~~~~~~~~ - `pytest-asyncio` no longer alters existing event loop policies. `#168 `_, `#188 `_ - Drop support for Python 3.6 +- Fixed an issue when pytest-asyncio was used in combination with `flaky` or inherited asynchronous Hypothesis tests. `#178 `_ `#231 `_ +- Added `flaky `_ to test dependencies 0.16.0 (2021-10-16) ~~~~~~~~~~~~~~~~~~~ diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 461bbe5f..634d1fb7 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -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): @@ -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) diff --git a/tests/test_hypothesis_integration.py b/tests/hypothesis/test_base.py similarity index 100% rename from tests/test_hypothesis_integration.py rename to tests/hypothesis/test_base.py diff --git a/tests/hypothesis/test_inherited_test.py b/tests/hypothesis/test_inherited_test.py new file mode 100644 index 00000000..86e92efd --- /dev/null +++ b/tests/hypothesis/test_inherited_test.py @@ -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