Skip to content

Commit

Permalink
Merge pull request #1557 from CuriousLearner/issue1547
Browse files Browse the repository at this point in the history
fix(core): HypothesisDeprecationWarning now gives indication of slow tests
  • Loading branch information
Zac-HD authored Sep 9, 2018
2 parents 2033bc0 + 796c72c commit e35bdd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: patch

This release adds the test name to some deprecation warnings,
for easier debugging.

Thanks to Sanyam Khurana for the patch!
32 changes: 17 additions & 15 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,14 @@ def test(*args, **kwargs):
):
self.__warned_deadline = True
note_deprecation((
'Test took %.2fms to run. In future the default '
'deadline setting will be 200ms, which will '
'make this an error. You can set deadline to '
'Test: %s took %.2fms to run. In future the '
'default deadline setting will be 200ms, which '
'will make this an error. You can set deadline to '
'an explicit value of e.g. %d to turn tests '
'slower than this into an error, or you can set '
'it to None to disable this check entirely.') % (
runtime, ceil(runtime / 100) * 100,
self.test.__name__, runtime,
ceil(runtime / 100) * 100,
))
else:
current_deadline = self.settings.deadline
Expand Down Expand Up @@ -601,18 +602,19 @@ def run(self):

if runner.used_examples_from_database:
if self.settings.derandomize:
note_deprecation(
note_deprecation((
'In future derandomize will imply database=None, but your '
'test is currently using examples from the database. To '
'get the future behaviour, update your settings to '
'include database=None.'
'test: %s is currently using examples from the database. '
'To get the future behaviour, update your settings to '
'include database=None.') % (self.test.__name__, )
)
if self.__had_seed:
note_deprecation(
note_deprecation((
'In future use of @seed will imply database=None in your '
'settings, but your test is currently using examples from '
'the database. To get the future behaviour, update your '
'settings for this test to include database=None.'
'settings, but your test: %s is currently using examples '
'from the database. To get the future behaviour, update '
'your settings for this test to include database=None.')
% (self.test.__name__,)
)

timed_out = runner.exit_reason == ExitReason.timeout
Expand Down Expand Up @@ -807,14 +809,14 @@ def wrapped_test(*arguments, **kwargs):
test = wrapped_test.hypothesis.inner_test

if getattr(test, 'is_hypothesis_test', False):
note_deprecation(
'You have applied @given to a test more than once. In '
note_deprecation((
'You have applied @given to test: %s more than once. In '
'future this will be an error. Applying @given twice '
'wraps the test twice, which can be extremely slow. A '
'similar effect can be gained by combining the arguments '
'of the two calls to given. For example, instead of '
'@given(booleans()) @given(integers()), you could write '
'@given(booleans(), integers())'
'@given(booleans(), integers())') % (test.__name__, )
)

settings = wrapped_test._hypothesis_internal_use_settings
Expand Down

0 comments on commit e35bdd5

Please sign in to comment.