Repository: HypothesisWorks/hypothesis

Issue:
HypothesisDeprecationWarning gives no indication of which test is slow
I have a handful of tests that sometimes trigger the `HypothesisDeprecationWarning` about tests being slow to run:

```
hypothesis_temporary_module_cba4de053ba62cfcdec02732278778740d129479:154: HypothesisDeprecationWarning: Test took 778.72ms 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. 800 to turn tests slower than this into an error, or you can set it to None to disable this check entirely.
```

However, the warning doesn't indicate which test is slow.  Is this fixable?

PS Thanks for Hypothesis!  It's second only to the Rust borrow checker for restoring in me a rightful sense of humility.


Discussion:
Well, running with warnings as errors would make it show in the traceback :wink: 

We can also fix this on our end, by adding `self.test.__name__` to all deprecation messages in `core.py`.  This would be a good issue for anyone who wants to get started with Hypothesis, or wants a fix released sooner!

(and thanks for the lovely PS!  mind if I add it to the testimonials page?)
It hadn't occurred to me to run with warnings as errors, but adding the test name to the message would be helpful in the case of nondeterministic warnings.

And yes about the testimonial.
I'm looking into this issue 🥇 

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/core.py b/hypothesis-python/src/hypothesis/core.py
--- a/hypothesis-python/src/hypothesis/core.py
+++ b/hypothesis-python/src/hypothesis/core.py
@@ -557,13 +557,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
@@ -767,18 +768,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
@@ -972,14 +974,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


Test patch: