Skip to content

Commit

Permalink
fix: Handle invalid Hypothesis tests during test generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Oct 2, 2020
1 parent 518faee commit b09cbce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/schemathesis/_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup_default_deadline(wrapped_test: Callable) -> None:
# Quite hacky, but it is the simplest way to set up the default deadline value without affecting non-Schemathesis
# tests globally
existing_settings = getattr(wrapped_test, "_hypothesis_internal_use_settings", None)
if existing_settings.deadline == hypothesis.settings.default.deadline:
if existing_settings is not None and existing_settings.deadline == hypothesis.settings.default.deadline:
new_settings = hypothesis.settings(existing_settings, deadline=DEFAULT_DEADLINE)
wrapped_test._hypothesis_internal_use_settings = new_settings # type: ignore

Expand Down
17 changes: 16 additions & 1 deletion test/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_d():
def test_schema_given(testdir):
# When the test uses `schema.given`
testdir.make_test(
f"""
"""
from hypothesis.strategies._internal.core import DataObject
@schema.parametrize()
Expand All @@ -161,3 +161,18 @@ def test(data, case):
# And be available in the test
result = testdir.runpytest()
result.assert_outcomes(passed=1)


def test_invalid_test(testdir):
# When the test doesn't use the strategy provided in `schema.given`
testdir.make_test(
"""
@schema.parametrize()
@schema.given(data=st.data())
def test(case):
pass
""",
)
# Then the test should fail instead of error
result = testdir.runpytest()
result.assert_outcomes(failed=1)

0 comments on commit b09cbce

Please sign in to comment.