How to use raise_hypothesis_usage_error method in hypothesis

Best Python code snippet using hypothesis

_hypothesis_pytestplugin.py

Source:_hypothesis_pytestplugin.py Github

copy

Full Screen

...161 if not is_hypothesis_test(item.obj):162 # If @given was not applied, check whether other hypothesis163 # decorators were applied, and raise an error if they were.164 # We add this frame of indirection to enable __tracebackhide__.165 def raise_hypothesis_usage_error(msg):166 raise InvalidArgument(msg)167 if getattr(item.obj, "is_hypothesis_strategy_function", False):168 from hypothesis.errors import InvalidArgument169 raise_hypothesis_usage_error(170 f"{item.nodeid} is a function that returns a Hypothesis strategy, "171 "but pytest has collected it as a test function. This is useless "172 "as the function body will never be executed. To define a test "173 "function, use @given instead of @composite."174 )175 message = "Using `@%s` on a test without `@given` is completely pointless."176 for name, attribute in [177 ("example", "hypothesis_explicit_examples"),178 ("seed", "_hypothesis_internal_use_seed"),179 ("settings", "_hypothesis_internal_settings_applied"),180 ("reproduce_example", "_hypothesis_internal_use_reproduce_failure"),181 ]:182 if hasattr(item.obj, attribute):183 from hypothesis.errors import InvalidArgument184 raise_hypothesis_usage_error(message % (name,))185 yield186 else:187 from hypothesis import HealthCheck, settings188 from hypothesis.internal.escalation import current_pytest_item189 from hypothesis.internal.healthcheck import fail_health_check190 from hypothesis.reporting import with_reporter191 from hypothesis.statistics import collector, describe_statistics192 # Retrieve the settings for this test from the test object, which193 # is normally a Hypothesis wrapped_test wrapper. If this doesn't194 # work, the test object is probably something weird195 # (e.g a stateful test wrapper), so we skip the function-scoped196 # fixture check.197 settings = getattr(item.obj, "_hypothesis_internal_use_settings", None)198 # Check for suspicious use of function-scoped fixtures, but only...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful