Skip to content

Commit

Permalink
fix: Use full_path in error messages in recoverable schema-level er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
Stranger6667 committed Feb 14, 2022
1 parent e933553 commit 375f4f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog

- Use the same ``correlation_id`` in ``BeforeExecution`` and ``AfterExecution`` events if the API schema contains an error that
causes an ``InvalidSchema`` exception during test execution.
- Use ``full_path`` in error messages in recoverable schema-level errors. It makes events generated in such cases consistent with usual events.

`3.13.1`_ - 2022-02-10
----------------------
Expand Down
2 changes: 1 addition & 1 deletion src/schemathesis/runner/impl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def handle_schema_error(
assert error.path is not None
assert error.full_path is not None
method = error.method.upper()
verbose_name = f"{method} {error.path}"
verbose_name = f"{method} {error.full_path}"
result = TestResult(
method=method,
path=error.full_path,
Expand Down
19 changes: 14 additions & 5 deletions test/cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,26 +1996,33 @@ def test_get_exit_code(swagger_20, capsys):
assert get_exit_code(event) == 1


@pytest.mark.parametrize("base_url", (None, "http://127.0.0.1/apiv2"))
@pytest.mark.parametrize("location", ("path", "query", "header", "cookie"))
def test_missing_content_and_schema(cli, tmp_path, testdir, empty_open_api_3_schema, location):
def test_missing_content_and_schema(cli, base_url, tmp_path, testdir, empty_open_api_3_schema, location):
debug_file = tmp_path / "debug.jsonl"
# When an Open API 3 parameter is missing `schema` & `content`
empty_open_api_3_schema["paths"] = {
"/foo": {"get": {"parameters": [{"in": location, "name": "X-Foo", "required": True}]}}
}
schema_file = testdir.makefile(".json", schema=json.dumps(empty_open_api_3_schema))
result = cli.run(
args = [
str(schema_file),
f"--debug-output-file={debug_file}",
"--dry-run",
"--validate-schema=false",
"--hypothesis-max-examples=1",
)
]
if base_url is not None:
args.append(f"--base-url={base_url}")
result = cli.run(*args)
lines = result.stdout.split("\n")
# Then CLI should show that this API operation errored
assert lines[10].startswith("GET /foo E")
# And show the proper message under its "ERRORS" section
assert "_ GET /foo [P] _" in lines[13]
if base_url is None:
assert lines[10].startswith("GET /foo E")
else:
assert lines[10].startswith("GET /apiv2/foo E")
assert "_ GET /apiv2/foo [P] _" in lines[13]
assert (
lines[14] == f'InvalidSchema: Can not generate data for {location} parameter "X-Foo"! '
"It should have either `schema` or `content` keywords defined"
Expand All @@ -2024,3 +2031,5 @@ def test_missing_content_and_schema(cli, tmp_path, testdir, empty_open_api_3_sch
with debug_file.open(encoding="utf-8") as fd:
events = [json.loads(line) for line in fd]
assert events[1]["correlation_id"] == events[2]["correlation_id"]
# And they should have the same "verbose_name"
assert events[1]["verbose_name"] == events[2]["verbose_name"]

0 comments on commit 375f4f6

Please sign in to comment.