diff --git a/docs/changelog.rst b/docs/changelog.rst index 5b085bbfc7..ee502c9b36 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,7 @@ Fixed - Crash on invalid value in ``header`` CLI options. `#405`_ - Crash on some invalid URLs in ``schema`` CLI option. `#406`_ - Validation of ``--request-timeout`` parameter. `#407`_ +- Crash with ``--hypothesis-deadline=0`` CLI option. `#410`_ `0.24.1`_ - 2020-02-08 ---------------------- @@ -696,6 +697,7 @@ Fixed .. _0.3.0: https://github.com/kiwicom/schemathesis/compare/v0.2.0...v0.3.0 .. _0.2.0: https://github.com/kiwicom/schemathesis/compare/v0.1.0...v0.2.0 +.. _#410: https://github.com/kiwicom/schemathesis/issues/410 .. _#407: https://github.com/kiwicom/schemathesis/issues/407 .. _#406: https://github.com/kiwicom/schemathesis/issues/406 .. _#405: https://github.com/kiwicom/schemathesis/issues/405 diff --git a/src/schemathesis/cli/__init__.py b/src/schemathesis/cli/__init__.py index 6f7a68a583..244168de0f 100644 --- a/src/schemathesis/cli/__init__.py +++ b/src/schemathesis/cli/__init__.py @@ -123,7 +123,7 @@ def schemathesis(pre_run: Optional[str] = None) -> None: @click.option( "--hypothesis-deadline", help="Duration in milliseconds that each individual example with a test is not allowed to exceed.", - type=OptionalInt(), + type=OptionalInt(1), ) @click.option("--hypothesis-derandomize", help="Use Hypothesis's deterministic mode.", is_flag=True, default=None) @click.option( diff --git a/src/schemathesis/cli/options.py b/src/schemathesis/cli/options.py index b339ff2565..a68f1a7ccc 100644 --- a/src/schemathesis/cli/options.py +++ b/src/schemathesis/cli/options.py @@ -29,13 +29,14 @@ class NotSet: not_set = NotSet() -class OptionalInt(click.types.IntParamType): +class OptionalInt(click.types.IntRange): def convert( # type: ignore self, value: str, param: Optional[click.core.Parameter], ctx: Optional[click.core.Context] ) -> Union[int, NotSet]: if value == "None": return not_set try: - return int(value) + int(value) + return super().convert(value, param, ctx) except (ValueError, UnicodeError): self.fail("%s is not a valid integer or None" % value, param, ctx) diff --git a/test/cli/test_commands.py b/test/cli/test_commands.py index fb7171fb5f..a705b34b3c 100644 --- a/test/cli/test_commands.py +++ b/test/cli/test_commands.py @@ -112,6 +112,10 @@ def test_commands_version(cli): ("run", "http://127.0.0.1", "--hypothesis-deadline=wrong"), 'Error: Invalid value for "--hypothesis-deadline": wrong is not a valid integer or None', ), + ( + ("run", "http://127.0.0.1", "--hypothesis-deadline=0"), + 'Error: Invalid value for "--hypothesis-deadline": 0 is smaller than the minimum valid value 1.', + ), ( ("run", "http://127.0.0.1", "--header=ั‚ะตัั‚:test"), 'Error: Invalid value for "--header" / "-H": Header name should be latin-1 encodable', @@ -170,7 +174,8 @@ def test_commands_run_help(cli): " during the test run.", " --validate-schema BOOLEAN Enable or disable validation of input schema.", " --show-errors-tracebacks Show full tracebacks for internal errors.", - " --hypothesis-deadline INTEGER Duration in milliseconds that each individual", + " --hypothesis-deadline INTEGER RANGE", + " Duration in milliseconds that each individual", " example with a test is not allowed to exceed.", " --hypothesis-derandomize Use Hypothesis's deterministic mode.", " --hypothesis-max-examples INTEGER", diff --git a/test/cli/test_crashes.py b/test/cli/test_crashes.py index 556eb30d16..892eea5c53 100644 --- a/test/cli/test_crashes.py +++ b/test/cli/test_crashes.py @@ -57,6 +57,7 @@ def paths(draw): "workers": st.integers(min_value=1, max_value=64), "request-timeout": st.integers(), "validate-schema": st.booleans(), + "hypothesis-deadline": st.integers() | st.none(), }, ).map(lambda params: [f"--{key}={value}" for key, value in params.items()]), flags=st.fixed_dictionaries( @@ -74,6 +75,7 @@ def paths(draw): ).map(lambda params: [f"--{key}={value}" for key, values in params.items() for value in values]), ) @example(params=[], flags=[], multiple_params=["--header=0:0\r"]) +@example(params=["--hypothesis-deadline=0"], flags=[], multiple_params=[]) @pytest.mark.usefixtures("mocked_schema") def test_valid_parameters_combos(cli, schema_url, params, flags, multiple_params): result = cli.run(schema_url, *params, *multiple_params, *flags)