Skip to content

Commit

Permalink
chore: Pass original InvalidSchema text to pytest.fail` call
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jun 15, 2020
1 parent 9f144a0 commit 40818f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changed
~~~~~~~

- Require ``hypothesis-jsonschema>=0.16``. `#614`_
- Pass original ``InvalidSchema`` text to ``pytest.fail`` call.

`1.7.0`_ - 2020-05-30
---------------------
Expand Down
5 changes: 3 additions & 2 deletions src/schemathesis/extra/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def _parametrize(
def _make_test(self, endpoint: Endpoint) -> Callable:
try:
return create_test(endpoint, self.test_function)
except InvalidSchema:
return lambda: pytest.fail("Invalid schema for endpoint")
except InvalidSchema as exc:
message = exc.args[0]
return lambda: pytest.fail(message)

def collect(self) -> List[Function]: # type: ignore
"""Generate different test items for all endpoints available in the given schema."""
Expand Down
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def make_importable_pyfile(*args, **kwargs):
def run_and_assert(*args, **kwargs):
result = testdir.runpytest(*args)
result.assert_outcomes(**kwargs)
return result

testdir.run_and_assert = run_and_assert

Expand Down
14 changes: 13 additions & 1 deletion test/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from copy import deepcopy
from urllib.parse import quote, unquote

import pytest
import yaml
Expand Down Expand Up @@ -341,3 +340,16 @@ def test(case):
assert isinstance(case.query["key"], str)

test()


def test_get_request_with_body(testdir, schema_with_get_payload):
testdir.make_test(
"""
@schema.parametrize()
def test_(case):
pass
""",
schema=schema_with_get_payload,
)
result = testdir.run_and_assert(failed=1)
result.stdout.re_match_lines([r"E Failed: Body parameters are defined for GET request."])

0 comments on commit 40818f9

Please sign in to comment.