Skip to content

Commit

Permalink
fix: Do not suggest to disable schema validation if it is already dis…
Browse files Browse the repository at this point in the history
…abled

Ref: #914
  • Loading branch information
Stranger6667 committed Dec 26, 2020
1 parent ffdcee6 commit a5d3c65
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -32,6 +32,7 @@ Changelog
- Excessive reference inlining that leads to out-of-memory for large schemas with deep references. `#945`_
- ``--exitfirst`` CLI option trims the progress bar output when a failure occurs. `#951`_
- Internal error if filling missing explicit examples led to ``Unsatisfiable`` errors. `#904`_
- Do not suggest to disable schema validation if it is already disabled. `#914`_

**Removed**

Expand Down Expand Up @@ -1626,6 +1627,7 @@ Deprecated
.. _#919: https://github.com/schemathesis/schemathesis/issues/919
.. _#917: https://github.com/schemathesis/schemathesis/issues/917
.. _#916: https://github.com/schemathesis/schemathesis/issues/916
.. _#914: https://github.com/schemathesis/schemathesis/issues/914
.. _#911: https://github.com/schemathesis/schemathesis/issues/911
.. _#904: https://github.com/schemathesis/schemathesis/issues/904
.. _#897: https://github.com/schemathesis/schemathesis/issues/897
Expand Down
6 changes: 5 additions & 1 deletion src/schemathesis/cli/__init__.py
Expand Up @@ -380,7 +380,9 @@ def run(
hypothesis_suppress_health_check=hypothesis_suppress_health_check,
hypothesis_verbosity=hypothesis_verbosity,
)
execute(prepared_runner, workers_num, show_errors_tracebacks, store_network_log, junit_xml, verbosity)
execute(
prepared_runner, workers_num, show_errors_tracebacks, validate_schema, store_network_log, junit_xml, verbosity
)


def check_auth(auth: Optional[Tuple[str, str]], headers: Dict[str, str]) -> None:
Expand Down Expand Up @@ -419,6 +421,7 @@ def execute(
prepared_runner: Generator[events.ExecutionEvent, None, None],
workers_num: int,
show_errors_tracebacks: bool,
validate_schema: bool,
store_network_log: Optional[click.utils.LazyFile],
junit_xml: Optional[click.utils.LazyFile],
verbosity: int,
Expand All @@ -434,6 +437,7 @@ def execute(
execution_context = ExecutionContext(
workers_num=workers_num,
show_errors_tracebacks=show_errors_tracebacks,
validate_schema=validate_schema,
cassette_file_name=store_network_log.name if store_network_log is not None else None,
junit_xml_file=junit_xml.name if junit_xml is not None else None,
verbosity=verbosity,
Expand Down
1 change: 1 addition & 0 deletions src/schemathesis/cli/context.py
Expand Up @@ -14,6 +14,7 @@ class ExecutionContext:
hypothesis_output: List[str] = attr.ib(factory=list) # pragma: no mutate
workers_num: int = attr.ib(default=1) # pragma: no mutate
show_errors_tracebacks: bool = attr.ib(default=False) # pragma: no mutate
validate_schema: bool = attr.ib(default=True) # pragma: no mutate
endpoints_processed: int = attr.ib(default=0) # pragma: no mutate
# It is set in runtime, from a `Initialized` event
endpoints_count: Optional[int] = attr.ib(default=None) # pragma: no mutate
Expand Down
2 changes: 1 addition & 1 deletion src/schemathesis/cli/output/default.py
Expand Up @@ -133,7 +133,7 @@ def display_single_error(context: ExecutionContext, result: SerializedTestResult
message = error.exception_with_traceback
else:
message = error.exception
if error.exception.startswith("schemathesis.exceptions.InvalidSchema"):
if error.exception.startswith("schemathesis.exceptions.InvalidSchema") and context.validate_schema:
message += DISABLE_SCHEMA_VALIDATION_MESSAGE + "\n"
click.secho(message, fg="red")
if error.example is not None:
Expand Down
11 changes: 11 additions & 0 deletions test/cli/test_commands.py
Expand Up @@ -691,6 +691,17 @@ def test_invalid_endpoint_suggestion(cli, cli_args):
assert expected in result.stdout


@pytest.mark.endpoints("invalid")
def test_invalid_endpoint_suggestion_disabled(cli, cli_args):
# When the app's schema contains errors
# And schema validation is disabled
result = cli.run(*cli_args, "--validate-schema=false")
# Then the whole Schemathesis run should fail
assert result.exit_code == ExitCode.TESTS_FAILED, result.stdout
# And there should be no suggestion
assert "You can disable input schema validation" not in result.stdout


@pytest.mark.endpoints("teapot")
@pytest.mark.parametrize("workers", (1, 2))
def test_status_code_conformance(cli, cli_args, workers):
Expand Down

0 comments on commit a5d3c65

Please sign in to comment.