Skip to content

Commit

Permalink
chore: Clarify error message on unsupported recursive references
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
  • Loading branch information
Stranger6667 committed May 8, 2024
1 parent c9dd8bb commit da74bc0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
**Changed**

- Do not show suggestion to show a traceback on Hypothesis' ``Unsatisfiable`` error.
- Clarify error message on unsupported recursive references.

.. _v3.27.1:

Expand Down
8 changes: 8 additions & 0 deletions src/schemathesis/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ def from_exc(cls, exc: hypothesis.errors.DeadlineExceeded) -> DeadlineExceeded:
)


class RecursiveReferenceError(Exception):
"""Recursive reference is impossible to resolve due to current limitations."""

__module__ = "builtins"


@enum.unique
class RuntimeErrorType(str, enum.Enum):
# Connection related issues
Expand All @@ -354,6 +360,7 @@ class RuntimeErrorType(str, enum.Enum):

SCHEMA_BODY_IN_GET_REQUEST = "schema_body_in_get_request"
SCHEMA_INVALID_REGULAR_EXPRESSION = "schema_invalid_regular_expression"
SCHEMA_UNSUPPORTED = "schema_unsupported"
SCHEMA_GENERIC = "schema_generic"

SERIALIZATION_NOT_POSSIBLE = "serialization_not_possible"
Expand All @@ -367,6 +374,7 @@ def has_useful_traceback(self) -> bool:
return self not in (
RuntimeErrorType.SCHEMA_BODY_IN_GET_REQUEST,
RuntimeErrorType.SCHEMA_INVALID_REGULAR_EXPRESSION,
RuntimeErrorType.SCHEMA_UNSUPPORTED,
RuntimeErrorType.SCHEMA_GENERIC,
RuntimeErrorType.SERIALIZATION_NOT_POSSIBLE,
)
Expand Down
3 changes: 2 additions & 1 deletion src/schemathesis/runner/impl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
InvalidRegularExpression,
NonCheckError,
OperationSchemaError,
RecursiveReferenceError,
SerializationNotPossible,
SkipTest,
format_exception,
Expand Down Expand Up @@ -480,7 +481,7 @@ def run_test(
result.add_error(error)
except HypothesisRefResolutionError:
status = Status.error
result.add_error(hypothesis.errors.Unsatisfiable(RECURSIVE_REFERENCE_ERROR_MESSAGE))
result.add_error(RecursiveReferenceError(RECURSIVE_REFERENCE_ERROR_MESSAGE))
except InvalidArgument as error:
status = Status.error
message = get_invalid_regular_expression_message(warnings)
Expand Down
6 changes: 6 additions & 0 deletions src/schemathesis/runner/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
InternalError,
InvalidRegularExpression,
OperationSchemaError,
RecursiveReferenceError,
RuntimeErrorType,
SerializationError,
UnboundPrefixError,
Expand Down Expand Up @@ -244,6 +245,11 @@ def from_exception(cls, exception: Exception) -> SerializedError:
type_ = RuntimeErrorType.HYPOTHESIS_DEADLINE_EXCEEDED
message = str(exception).strip()
extras = []
elif isinstance(exception, RecursiveReferenceError):
type_ = RuntimeErrorType.SCHEMA_UNSUPPORTED
message = str(exception).strip()
extras = []
title = "Unsupported Schema"
elif isinstance(exception, hypothesis.errors.InvalidArgument) and str(exception).startswith("Scalar "):
# Comes from `hypothesis-graphql`
scalar_name = _scalar_name_from_error(exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Exit code: 1
---
Stdout:
======================= Schemathesis test session starts =======================
Schema location: file:///tmp/schema.json
Base URL: http://127.0.0.1/api
Specification version: Open API 3.0.0
Random seed: 42
Workers: 1
Collected API operations: 1
Collected API links: 0
API probing: SUCCESS
Schema analysis: SKIP

POST /api/foo E [100%]

==================================== ERRORS ====================================
________________________________ POST /api/foo _________________________________
Unsupported Schema

Currently, Schemathesis can't generate data for this operation due to recursive references in the operation definition. See more information in this issue - https://github.com/schemathesis/schemathesis/issues/947

Need more help?
Join our Discord server: https://discord.gg/R9ASRAmHnA
=================================== SUMMARY ====================================

No checks were performed.

Tip: Use the `--report` CLI option to visualize test results via Schemathesis.io.
We run additional conformance checks on reports from public repos.

============================== 1 errored in 1.00s ==============================
8 changes: 8 additions & 0 deletions test/cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,3 +2378,11 @@ def no_null_bytes(response, case):
)
== snapshot_cli
)


@pytest.mark.skipif(platform.system() == "Windows", reason="Fails on Windows due to recursion")
def test_recursive_reference_error_message(
cli, testdir, schema_with_recursive_references, openapi3_base_url, snapshot_cli
):
schema_file = testdir.make_openapi_schema_file(schema_with_recursive_references)
assert cli.run(str(schema_file), f"--base-url={openapi3_base_url}", "--show-trace") == snapshot_cli

0 comments on commit da74bc0

Please sign in to comment.