Skip to content

Commit

Permalink
Add a test & readme clarification about schemas in lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry.dygalo committed Sep 24, 2019
1 parent 8e908b3 commit c4c6aca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ like ``apispec`` and requires an application instance available, then you can pa
In this case the test body will be used as a sub-test via ``pytest-subtests`` library.

**NOTE**: the used fixture should return a valid schema that could be created via ``schemathesis.from_dict`` or other
``schemathesis.from_`` variations.

Documentation
-------------

Expand Down
28 changes: 28 additions & 0 deletions test/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,31 @@ def test_(request, case, another):
result.assert_outcomes(passed=1)
result.stdout.re_match_lines([r"test_with_fixtures.py::test_ PASSED", r".*1 passed"])
result.stdout.re_match_lines([r"Hypothesis calls: 1"])


def test_invalid_fixture(testdir):
# When the test uses a schema fixture that doesn't return a BaseSchema subtype
testdir.make_test(
"""
@pytest.fixture
def simple_schema():
return 1
lazy_schema = schemathesis.from_pytest_fixture("simple_schema")
@lazy_schema.parametrize()
def test_(request, case):
request.config.HYPOTHESIS_CASES += 1
"""
)
result = testdir.runpytest("-v")
# Then the generated test should use these fixtures
result.assert_outcomes(failed=1)
result.stdout.re_match_lines(
[
r"test_invalid_fixture.py::test_ FAILED",
".*ValueError: The given schema must be an instance of BaseSchema, got: <class 'int'>",
r".*1 failed",
]
)

0 comments on commit c4c6aca

Please sign in to comment.