You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pytest will happily collect test_data_factory, execute it, and report it as a passing test... even if you replace the function body with assert False! This is because calling the function returns a LazyStrategy object, and the function isn't actually executed until later. More generally, it's because @composite should not be used to define test functions!
So it would be good to add a check to our pytest plugin, in pytest_collection_modifyitems, that replaces the collected item.obj with a function that will (a) fail, and (b) do so with a useful error suggesting that the user either rename the strategy or if intending to execute it as a test use @given(st.data()) instead.
The text was updated successfully, but these errors were encountered:
From #1658, occasionally users use
@composite
when they should be using@given(st.data())
. Unfortunately, this silently goes wrong:Pytest will happily collect
test_data_factory
, execute it, and report it as a passing test... even if you replace the function body withassert False
! This is because calling the function returns aLazyStrategy
object, and the function isn't actually executed until later. More generally, it's because@composite
should not be used to define test functions!So it would be good to add a check to our pytest plugin, in
pytest_collection_modifyitems
, that replaces the collecteditem.obj
with a function that will (a) fail, and (b) do so with a useful error suggesting that the user either rename the strategy or if intending to execute it as a test use@given(st.data())
instead.The text was updated successfully, but these errors were encountered: