Closed
Description
Initially reported in HypothesisWorks/hypothesis#3850
The bug can be reproduced by installing pytest_asyncio and hypothesis, then trying to run the following test:
from hypothesis.stateful import RuleBasedStateMachine class StatefulTest(RuleBasedStateMachine): def __init__(self): super().__init__() TestStorage = StatefulTest.TestCase
INTERNALERROR> Traceback (most recent call last): INTERNALERROR> ... INTERNALERROR> File ".../python3.11/site-packages/pytest_asyncio/plugin.py", line 371, in pytest_collection_modifyitems INTERNALERROR> and _hypothesis_test_wraps_coroutine(function) INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ INTERNALERROR> File ".../python3.11/site-packages/pytest_asyncio/plugin.py", line 377, in _hypothesis_test_wraps_coroutine INTERNALERROR> return _is_coroutine(function.hypothesis.inner_test) INTERNALERROR> ^^^^^^^^^^^^^^^^^^^ INTERNALERROR> AttributeError: 'function' object has no attribute 'hypothesis'
To fix this, we should avoid assuming that the .hypothesis
attribute exists in
pytest-asyncio/pytest_asyncio/plugin.py
Lines 482 to 487 in 463ce98
As a fix, I'd suggest:
return (
getattr(func, "is_hypothesis_test", False)
and getattr(func, "hypothesis", None)
and asyncio.iscoroutinefunction(func.hypothesis.inner_test)
)
Note that there's no simple to support async stateful testing; the hypothesis-trio
project is essentially a fork of our upstream stateful testing module with async handling injected in many places. My suggestion therefore continues to treat asyncio stateful tests as out of scope, since I don't think there's sufficient demand to be worth the maintainence burden.
Metadata
Metadata
Assignees
Labels
No labels