-1

Is there a way to use Hypothesis to check if a Python function raises an Error when a particular set of arguments are passed to it? As in, I want the assert to be True if the function fails and not make the test execution stop and the function marked as having failed.

Pratyush Das
  • 460
  • 7
  • 24

1 Answers1

0

Yes, just as you would for a non-Hypothesis test! For example, you could use with pytest.raises(...):, or try: ... ; except: pass ; else: raise AssertionError("did not raise error").

If you mean that it is only expected to fail with an exact set of arguments, this seems like a case for traditional example-based tests; if you mean some arguments and not others I'd write a separate test for each case but you could get away with an if statement too.

Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19