item = <Function test_journal_client_linux>
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
if not hasattr(item, "obj"):
yield
elif not is_hypothesis_test(item.obj):
# If @given was not applied, check whether other hypothesis
# decorators were applied, and raise an error if they were.
if getattr(item.obj, "is_hypothesis_strategy_function", False):
raise InvalidArgument(
"%s is a function that returns a Hypothesis strategy, but pytest "
"has collected it as a test function. This is useless as the "
"function body will never be executed. To define a test "
"function, use @given instead of @composite." % (item.nodeid,)
)
message = "Using `@%s` on a test without `@given` is completely pointless."
for name, attribute in [
("example", "hypothesis_explicit_examples"),
("seed", "_hypothesis_internal_use_seed"),
("settings", "_hypothesis_internal_settings_applied"),
("reproduce_example", "_hypothesis_internal_use_reproduce_failure"),
]:
if hasattr(item.obj, attribute):
raise InvalidArgument(message % (name,))
yield
else:
# Retrieve the settings for this test from the test object, which
# is normally a Hypothesis wrapped_test wrapper. If this doesn't
# work, the test object is probably something weird
# (e.g a stateful test wrapper), so we skip the function-scoped
# fixture check.
settings = getattr(item.obj, "_hypothesis_internal_use_settings", None)
# Check for suspicious use of function-scoped fixtures, but only
# if the corresponding health check is not suppressed.
if (
settings is not None
and HealthCheck.function_scoped_fixture
not in settings.suppress_health_check
):
# Warn about function-scoped fixtures, excluding autouse fixtures because
# the advice is probably not actionable and the status quo seems OK...
# See https://github.com/HypothesisWorks/hypothesis/issues/377 for detail.
msg = (
"%s uses the %r fixture, which is reset between function calls but not "
"between test cases generated by `@given(...)`. You can change it to "
"a module- or session-scoped fixture if it is safe to reuse; if not "
"we recommend using a context manager inside your test function. See "
"https://docs.pytest.org/en/latest/fixture.html#sharing-test-data "
"for details on fixture scope."
)
argnames = None
for fx_defs in item._request._fixturemanager.getfixtureinfo(
node=item, func=item.function, cls=None
).name2fixturedefs.values():
if argnames is None:
argnames = frozenset(signature(item.function).parameters)
for fx in fx_defs:
if fx.argname in argnames:
active_fx = item._request._get_active_fixturedef(fx.argname)
if active_fx.scope == "function":
fail_health_check(
settings,
msg % (item.nodeid, fx.argname),
> HealthCheck.function_scoped_fixture,
)
E hypothesis.errors.FailedHealthCheck: .tox/py3/lib/python3.7/site-packages/swh/scheduler/tests/test_journal_client.py::test_journal_client_linux uses the 'swh_scheduler' fixture, which is reset between function calls but not between test cases generated by `@given(...)`. You can change it to a module- or session-scoped fixture if it is safe to reuse; if not we recommend using a context manager inside your test function. See https://docs.pytest.org/en/latest/fixture.html#sharing-test-data for details on fixture scope.
E See https://hypothesis.readthedocs.io/en/latest/healthchecks.html for more information about this. If you want to disable just this health check, add HealthCheck.function_scoped_fixture to the suppress_health_check settings for this test.
.tox/py3/lib/python3.7/site-packages/hypothesis/extra/pytestplugin.py:185: FailedHealthCheck
TEST RESULT
TEST RESULT
- Run At
- Feb 1 2021, 2:13 PM