Skip to content

Commit 2b9506b

Browse files
committed
Make timeout setting a no-op
1 parent 8431a80 commit 2b9506b

23 files changed

+44
-451
lines changed

hypothesis-python/docs/settings.rst

-43
Original file line numberDiff line numberDiff line change
@@ -216,46 +216,3 @@ by your conftest you can load one with the command line option ``--hypothesis-pr
216216
.. code:: bash
217217
218218
$ pytest tests --hypothesis-profile <profile-name>
219-
220-
221-
~~~~~~~~
222-
Timeouts
223-
~~~~~~~~
224-
225-
The timeout functionality of Hypothesis is being deprecated, and will
226-
eventually be removed. For the moment, the timeout setting can still be set
227-
and the old default timeout of one minute remains.
228-
229-
If you want to future proof your code you can get
230-
the future behaviour by setting it to the value ``hypothesis.unlimited``.
231-
232-
.. code:: python
233-
234-
from hypothesis import given, settings, unlimited
235-
from hypothesis import strategies as st
236-
237-
@settings(timeout=unlimited)
238-
@given(st.integers())
239-
def test_something_slow(i):
240-
...
241-
242-
This will cause your code to run until it hits the normal Hypothesis example
243-
limits, regardless of how long it takes. ``timeout=unlimited`` will remain a
244-
valid setting after the timeout functionality has been deprecated (but will
245-
then have its own deprecation cycle).
246-
247-
There is however now a timing related health check which is designed to catch
248-
tests that run for ages by accident. If you really want your test to run
249-
forever, the following code will enable that:
250-
251-
.. code:: python
252-
253-
from hypothesis import given, settings, unlimited, HealthCheck
254-
from hypothesis import strategies as st
255-
256-
@settings(timeout=unlimited, suppress_health_check=[
257-
HealthCheck.hung_test
258-
])
259-
@given(st.integers())
260-
def test_something_slow(i):
261-
...

hypothesis-python/scripts/unicodechecker.py

-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import unicodenazi
2727

28-
from hypothesis import settings, unlimited
2928
from hypothesis.configuration import set_hypothesis_home_dir
3029
from hypothesis.errors import HypothesisDeprecationWarning
3130

@@ -36,12 +35,6 @@
3635

3736
set_hypothesis_home_dir(mkdtemp())
3837

39-
assert isinstance(settings, type)
40-
41-
settings.register_profile("default", settings(timeout=unlimited))
42-
settings.load_profile("default")
43-
44-
4538
TESTS = ["test_testdecorators"]
4639

4740
sys.path.append(os.path.join("tests", "cover"))

hypothesis-python/src/hypothesis/_settings.py

+6-26
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ def _define_setting(
304304
future_default=not_set,
305305
deprecation_message=None,
306306
deprecated_since=None,
307-
hide_repr=not_set,
308307
):
309308
"""Add a new setting.
310309
@@ -326,9 +325,6 @@ def _define_setting(
326325
if future_default is not_set:
327326
future_default = default
328327

329-
if hide_repr is not_set:
330-
hide_repr = bool(deprecation_message)
331-
332328
all_settings[name] = Setting(
333329
name=name,
334330
description=description.strip(),
@@ -338,7 +334,6 @@ def _define_setting(
338334
future_default=future_default,
339335
deprecation_message=deprecation_message,
340336
deprecated_since=deprecated_since,
341-
hide_repr=hide_repr,
342337
)
343338
setattr(settings, name, settingsProperty(name, show_default))
344339

@@ -372,7 +367,7 @@ def __repr__(self):
372367
value = getattr(self, name)
373368
# The only settings that are not shown are those that are
374369
# deprecated and left at their default values.
375-
if value != setting.default or not setting.hide_repr:
370+
if value != setting.default or not setting.deprecation_message:
376371
bits.append("%s=%r" % (name, value))
377372
return "settings(%s)" % ", ".join(sorted(bits))
378373

@@ -473,7 +468,6 @@ class Setting(object):
473468
future_default = attr.ib()
474469
deprecation_message = attr.ib()
475470
deprecated_since = attr.ib()
476-
hide_repr = attr.ib()
477471

478472

479473
settings._define_setting(
@@ -539,31 +533,17 @@ class Setting(object):
539533

540534

541535
def _validate_timeout(n):
542-
if n is unlimited:
543-
return -1
544-
else:
536+
if n in (not_set, unlimited):
545537
return n
538+
raise InvalidArgument("The timeout setting has been removed.")
546539

547540

548541
settings._define_setting(
549542
"timeout",
550-
default=60,
551-
description="""
552-
Once this many seconds have passed, falsify will terminate even
553-
if it has not found many examples. This is a soft rather than a hard
554-
limit - Hypothesis won't e.g. interrupt execution of the called
555-
function to stop it. If this value is <= 0 then no timeout will be
556-
applied.
557-
""",
558-
hide_repr=False, # Still affects behaviour at runtime
559-
deprecation_message="""
560-
The timeout setting is deprecated and will be removed in a future version of
561-
Hypothesis. To get the future behaviour set ``timeout=hypothesis.unlimited``
562-
instead (which will remain valid for a further deprecation period after this
563-
setting has gone away).
564-
""",
543+
default=not_set,
544+
description="The timeout setting has been deprecated and no longer does anything.",
545+
deprecation_message="The timeout setting can safely be removed with no effect.",
565546
deprecated_since="2017-11-02",
566-
future_default=unlimited,
567547
validator=_validate_timeout,
568548
)
569549

hypothesis-python/src/hypothesis/core.py

+8-41
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
InvalidArgument,
5656
MultipleFailures,
5757
NoSuchExample,
58-
Timeout,
5958
Unsatisfiable,
6059
UnsatisfiedAssumption,
6160
)
@@ -647,7 +646,6 @@ def run(self):
647646
database_key = function_digest(self.test)
648647
else:
649648
database_key = None
650-
self.start_time = benchmark_time()
651649
runner = ConjectureRunner(
652650
self.evaluate_test_data,
653651
settings=self.settings,
@@ -659,7 +657,6 @@ def run(self):
659657
finally:
660658
self.used_examples_from_database = runner.used_examples_from_database
661659
note_engine_for_statistics(runner)
662-
run_time = benchmark_time() - self.start_time
663660

664661
self.used_examples_from_database = runner.used_examples_from_database
665662

@@ -687,7 +684,6 @@ def run(self):
687684
since="2017-11-29",
688685
)
689686

690-
timed_out = runner.exit_reason == ExitReason.timeout
691687
if runner.call_count == 0:
692688
return
693689
if runner.interesting_examples:
@@ -698,23 +694,10 @@ def run(self):
698694
)
699695
else:
700696
if runner.valid_examples == 0:
701-
if timed_out:
702-
raise Timeout(
703-
(
704-
"Ran out of time before finding a satisfying "
705-
"example for %s. Only found %d examples in %.2fs."
706-
)
707-
% (
708-
get_pretty_function_description(self.test),
709-
runner.valid_examples,
710-
run_time,
711-
)
712-
)
713-
else:
714-
raise Unsatisfiable(
715-
"Unable to satisfy assumptions of hypothesis %s."
716-
% (get_pretty_function_description(self.test),)
717-
)
697+
raise Unsatisfiable(
698+
"Unable to satisfy assumptions of hypothesis %s."
699+
% (get_pretty_function_description(self.test),)
700+
)
718701

719702
if not self.falsifying_examples:
720703
return
@@ -1142,13 +1125,11 @@ def template_condition(data):
11421125
if success and not data.frozen:
11431126
data.mark_interesting()
11441127

1145-
start = benchmark_time()
11461128
runner = ConjectureRunner(
11471129
template_condition, settings=settings, random=random, database_key=database_key
11481130
)
11491131
runner.run()
11501132
note_engine_for_statistics(runner)
1151-
run_time = benchmark_time() - start
11521133
if runner.interesting_examples:
11531134
data = ConjectureData.for_buffer(
11541135
list(runner.interesting_examples.values())[0].buffer
@@ -1157,23 +1138,9 @@ def template_condition(data):
11571138
with deterministic_PRNG():
11581139
return data.draw(search)
11591140
if runner.valid_examples == 0 and (runner.exit_reason != ExitReason.finished):
1160-
if settings.timeout > 0 and run_time > settings.timeout:
1161-
raise Timeout(
1162-
( # pragma: no cover
1163-
"Ran out of time before finding enough valid examples for "
1164-
"%s. Only %d valid examples found in %.2f seconds."
1165-
)
1166-
% (
1167-
get_pretty_function_description(condition),
1168-
runner.valid_examples,
1169-
run_time,
1170-
)
1171-
)
1172-
1173-
else:
1174-
raise Unsatisfiable(
1175-
"Unable to satisfy assumptions of %s."
1176-
% (get_pretty_function_description(condition),)
1177-
)
1141+
raise Unsatisfiable(
1142+
"Unable to satisfy assumptions of %s."
1143+
% (get_pretty_function_description(condition),)
1144+
)
11781145

11791146
raise NoSuchExample(get_pretty_function_description(condition))

hypothesis-python/src/hypothesis/internal/conjecture/engine.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import attr
2525

2626
from hypothesis import HealthCheck, Phase, Verbosity, settings as Settings
27-
from hypothesis._settings import local_settings, note_deprecation
27+
from hypothesis._settings import local_settings
2828
from hypothesis.internal.compat import (
2929
Counter,
3030
benchmark_time,
@@ -70,7 +70,6 @@ class HealthCheckState(object):
7070
class ExitReason(Enum):
7171
max_examples = 0
7272
max_iterations = 1
73-
timeout = 2
7473
max_shrinks = 3
7574
finished = 4
7675
flaky = 5
@@ -213,26 +212,6 @@ def test_function(self, data):
213212

214213
if self.shrinks >= MAX_SHRINKS:
215214
self.exit_with(ExitReason.max_shrinks)
216-
if (
217-
self.settings.timeout > 0
218-
and benchmark_time() >= self.start_time + self.settings.timeout
219-
):
220-
note_deprecation(
221-
(
222-
"Your tests are hitting the settings timeout (%.2fs). "
223-
"This functionality will go away in a future release "
224-
"and you should not rely on it. Instead, try setting "
225-
"max_examples to be some value lower than %d (the number "
226-
"of examples your test successfully ran here). Or, if you "
227-
"would prefer your tests to run to completion, regardless "
228-
"of how long they take, you can set the timeout value to "
229-
"hypothesis.unlimited."
230-
)
231-
% (self.settings.timeout, self.valid_examples),
232-
since="2018-07-29",
233-
verbosity=self.settings.verbosity,
234-
)
235-
self.exit_with(ExitReason.timeout)
236215

237216
if not self.interesting_examples:
238217
if self.valid_examples >= self.settings.max_examples:

hypothesis-python/src/hypothesis/stateful.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
Verbosity,
4040
note_deprecation,
4141
settings as Settings,
42-
unlimited,
4342
)
4443
from hypothesis.control import current_build_context
4544
from hypothesis.core import given
@@ -83,11 +82,7 @@ def run_state_machine_as_test(state_machine_factory, settings=None):
8382
settings = state_machine_factory.TestCase.settings
8483
check_type(Settings, settings, "state_machine_factory.TestCase.settings")
8584
except AttributeError:
86-
settings = Settings(
87-
timeout=unlimited,
88-
deadline=None,
89-
suppress_health_check=HealthCheck.all(),
90-
)
85+
settings = Settings(deadline=None, suppress_health_check=HealthCheck.all())
9186
check_type(Settings, settings, "settings")
9287

9388
@settings
@@ -229,11 +224,7 @@ def _to_test_case(state_machine_class):
229224
pass
230225

231226
class StateMachineTestCase(TestCase):
232-
settings = Settings(
233-
timeout=unlimited,
234-
deadline=None,
235-
suppress_health_check=HealthCheck.all(),
236-
)
227+
settings = Settings(deadline=None, suppress_health_check=HealthCheck.all())
237228

238229
# We define this outside of the class and assign it because you can't
239230
# assign attributes to instance method values in Python 2

hypothesis-python/tests/common/debug.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from __future__ import absolute_import, division, print_function
1919

20-
from hypothesis import assume, find, given, reject, settings as Settings, unlimited
20+
from hypothesis import assume, find, given, reject, settings as Settings
2121
from hypothesis.errors import NoSuchExample, Unsatisfiable
2222
from tests.common.utils import no_shrink
2323

@@ -29,7 +29,7 @@ class Timeout(BaseException):
2929

3030

3131
def minimal(definition, condition=None, settings=None, timeout_after=10, random=None):
32-
settings = Settings(settings, max_examples=50000, database=None, timeout=unlimited)
32+
settings = Settings(settings, max_examples=50000, database=None)
3333

3434
runtime = []
3535

@@ -53,9 +53,7 @@ def wrapped_condition(x):
5353

5454

5555
def find_any(definition, condition=None, settings=None, random=None):
56-
settings = Settings(
57-
settings, max_examples=10000, phases=no_shrink, database=None, timeout=unlimited
58-
)
56+
settings = Settings(settings, max_examples=10000, phases=no_shrink, database=None)
5957

6058
if condition is None:
6159

hypothesis-python/tests/common/setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from tempfile import mkdtemp
2222
from warnings import filterwarnings
2323

24-
from hypothesis import Verbosity, settings, unlimited
24+
from hypothesis import Verbosity, settings
2525
from hypothesis._settings import not_set
2626
from hypothesis.configuration import set_hypothesis_home_dir
2727
from hypothesis.internal.charmap import charmap, charmap_file
@@ -84,8 +84,7 @@ def run():
8484
)
8585

8686
settings.register_profile(
87-
"default",
88-
settings(max_examples=10 if IN_COVERAGE_TESTS else not_set, timeout=unlimited),
87+
"default", settings(max_examples=10 if IN_COVERAGE_TESTS else not_set)
8988
)
9089

9190
settings.register_profile("speedy", settings(max_examples=5))

0 commit comments

Comments
 (0)