We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add compat with pytest-capturelog for note()-style logging capture?
Using hypothesis with code that has logging statements makes it very difficult to use those log calls to debug.

Having the ability to have logging output captured in the style of `note()` would be extremely useful. The [pytest-capturelog](https://pypi.python.org/pypi/pytest-capturelog) plugin collects the logging output into the test failure message. It would be really nice to have some kind of cross-compatibility with them so that it can group captured logs by example rather than at the test-function level


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hypothesis-python/src/hypothesis/control.py`
Content:
```
1 # coding=utf-8
2 #
3 # This file is part of Hypothesis, which may be found at
4 # https://github.com/HypothesisWorks/hypothesis-python
5 #
6 # Most of this work is copyright (C) 2013-2018 David R. MacIver
7 # (david@drmaciver.com), but it contains contributions by others. See
8 # CONTRIBUTING.rst for a full list of people who may hold copyright, and
9 # consult the git log if you need to determine who owns an individual
10 # contribution.
11 #
12 # This Source Code Form is subject to the terms of the Mozilla Public License,
13 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
14 # obtain one at http://mozilla.org/MPL/2.0/.
15 #
16 # END HEADER
17 
18 from __future__ import division, print_function, absolute_import
19 
20 import traceback
21 
22 from hypothesis import Verbosity, settings
23 from hypothesis.errors import CleanupFailed, InvalidArgument, \
24     UnsatisfiedAssumption
25 from hypothesis.reporting import report
26 from hypothesis.utils.dynamicvariables import DynamicVariable
27 
28 if False:
29     from typing import Any, AnyStr  # noqa
30 
31 
32 def reject():
33     raise UnsatisfiedAssumption()
34 
35 
36 def assume(condition):
37     # type: (Any) -> bool
38     """Calling ``assume`` is like an :ref:`assert <python:assert>` that marks
39     the example as bad, rather than failing the test.
40 
41     This allows you to specify properties that you *assume* will be
42     true, and let Hypothesis try to avoid similar examples in future.
43     """
44     if not condition:
45         raise UnsatisfiedAssumption()
46     return True
47 
48 
49 _current_build_context = DynamicVariable(None)
50 
51 
52 def current_build_context():
53     context = _current_build_context.value
54     if context is None:
55         raise InvalidArgument(
56             u'No build context registered')
57     return context
58 
59 
60 class BuildContext(object):
61 
62     def __init__(self, data, is_final=False, close_on_capture=True):
63         self.data = data
64         self.tasks = []
65         self.is_final = is_final
66         self.close_on_capture = close_on_capture
67         self.close_on_del = False
68         self.notes = []
69 
70     def __enter__(self):
71         self.assign_variable = _current_build_context.with_value(self)
72         self.assign_variable.__enter__()
73         return self
74 
75     def __exit__(self, exc_type, exc_value, tb):
76         self.assign_variable.__exit__(exc_type, exc_value, tb)
77         if self.close() and exc_type is None:
78             raise CleanupFailed()
79 
80     def local(self):
81         return _current_build_context.with_value(self)
82 
83     def close(self):
84         any_failed = False
85         for task in self.tasks:
86             try:
87                 task()
88             except BaseException:
89                 any_failed = True
90                 report(traceback.format_exc())
91         return any_failed
92 
93 
94 def cleanup(teardown):
95     """Register a function to be called when the current test has finished
96     executing. Any exceptions thrown in teardown will be printed but not
97     rethrown.
98 
99     Inside a test this isn't very interesting, because you can just use
100     a finally block, but note that you can use this inside map, flatmap,
101     etc. in order to e.g. insist that a value is closed at the end.
102     """
103     context = _current_build_context.value
104     if context is None:
105         raise InvalidArgument(
106             u'Cannot register cleanup outside of build context')
107     context.tasks.append(teardown)
108 
109 
110 def note(value):
111     # type: (AnyStr) -> None
112     """Report this value in the final execution."""
113     context = _current_build_context.value
114     if context is None:
115         raise InvalidArgument(
116             'Cannot make notes outside of a test')
117     context.notes.append(value)
118     if context.is_final or settings.default.verbosity >= Verbosity.verbose:
119         report(value)
120 
121 
122 def event(value):
123     # type: (AnyStr) -> None
124     """Record an event that occurred this test. Statistics on number of test
125     runs with each event will be reported at the end if you run Hypothesis in
126     statistics reporting mode.
127 
128     Events should be strings or convertible to them.
129     """
130     context = _current_build_context.value
131     if context is None:
132         raise InvalidArgument(
133             'Cannot make record events outside of a test')
134 
135     if context.data is not None:
136         context.data.note_event(value)
137
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/hypothesis-python/src/hypothesis/control.py b/hypothesis-python/src/hypothesis/control.py
--- a/hypothesis-python/src/hypothesis/control.py
+++ b/hypothesis-python/src/hypothesis/control.py
@@ -17,6 +17,7 @@
 
 from __future__ import division, print_function, absolute_import
 
+import logging
 import traceback
 
 from hypothesis import Verbosity, settings
@@ -66,14 +67,20 @@
         self.close_on_capture = close_on_capture
         self.close_on_del = False
         self.notes = []
+        self.original_logging_disable = logging.NOTSET
 
     def __enter__(self):
+        if not self.is_final:
+            self.original_logging_disable = logging.root.manager.disable
+            logging.disable(logging.CRITICAL)
         self.assign_variable = _current_build_context.with_value(self)
         self.assign_variable.__enter__()
         return self
 
     def __exit__(self, exc_type, exc_value, tb):
         self.assign_variable.__exit__(exc_type, exc_value, tb)
+        if not self.is_final:
+            logging.disable(self.original_logging_disable)
         if self.close() and exc_type is None:
             raise CleanupFailed()

{"golden_diff": "diff --git a/hypothesis-python/src/hypothesis/control.py b/hypothesis-python/src/hypothesis/control.py\n--- a/hypothesis-python/src/hypothesis/control.py\n+++ b/hypothesis-python/src/hypothesis/control.py\n@@ -17,6 +17,7 @@\n \n from __future__ import division, print_function, absolute_import\n \n+import logging\n import traceback\n \n from hypothesis import Verbosity, settings\n@@ -66,14 +67,20 @@\n         self.close_on_capture = close_on_capture\n         self.close_on_del = False\n         self.notes = []\n+        self.original_logging_disable = logging.NOTSET\n \n     def __enter__(self):\n+        if not self.is_final:\n+            self.original_logging_disable = logging.root.manager.disable\n+            logging.disable(logging.CRITICAL)\n         self.assign_variable = _current_build_context.with_value(self)\n         self.assign_variable.__enter__()\n         return self\n \n     def __exit__(self, exc_type, exc_value, tb):\n         self.assign_variable.__exit__(exc_type, exc_value, tb)\n+        if not self.is_final:\n+            logging.disable(self.original_logging_disable)\n         if self.close() and exc_type is None:\n             raise CleanupFailed()\n", "issue": "Add compat with pytest-capturelog for note()-style logging capture?\nUsing hypothesis with code that has logging statements makes it very difficult to use those log calls to debug.\n\nHaving the ability to have logging output captured in the style of `note()` would be extremely useful. The [pytest-capturelog](https://pypi.python.org/pypi/pytest-capturelog) plugin collects the logging output into the test failure message. It would be really nice to have some kind of cross-compatibility with them so that it can group captured logs by example rather than at the test-function level\n\n", "before_files": [{"content": "# coding=utf-8\n#\n# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis-python\n#\n# Most of this work is copyright (C) 2013-2018 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# CONTRIBUTING.rst for a full list of people who may hold copyright, and\n# consult the git log if you need to determine who owns an individual\n# contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at http://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom __future__ import division, print_function, absolute_import\n\nimport traceback\n\nfrom hypothesis import Verbosity, settings\nfrom hypothesis.errors import CleanupFailed, InvalidArgument, \\\n    UnsatisfiedAssumption\nfrom hypothesis.reporting import report\nfrom hypothesis.utils.dynamicvariables import DynamicVariable\n\nif False:\n    from typing import Any, AnyStr  # noqa\n\n\ndef reject():\n    raise UnsatisfiedAssumption()\n\n\ndef assume(condition):\n    # type: (Any) -> bool\n    \"\"\"Calling ``assume`` is like an :ref:`assert <python:assert>` that marks\n    the example as bad, rather than failing the test.\n\n    This allows you to specify properties that you *assume* will be\n    true, and let Hypothesis try to avoid similar examples in future.\n    \"\"\"\n    if not condition:\n        raise UnsatisfiedAssumption()\n    return True\n\n\n_current_build_context = DynamicVariable(None)\n\n\ndef current_build_context():\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            u'No build context registered')\n    return context\n\n\nclass BuildContext(object):\n\n    def __init__(self, data, is_final=False, close_on_capture=True):\n        self.data = data\n        self.tasks = []\n        self.is_final = is_final\n        self.close_on_capture = close_on_capture\n        self.close_on_del = False\n        self.notes = []\n\n    def __enter__(self):\n        self.assign_variable = _current_build_context.with_value(self)\n        self.assign_variable.__enter__()\n        return self\n\n    def __exit__(self, exc_type, exc_value, tb):\n        self.assign_variable.__exit__(exc_type, exc_value, tb)\n        if self.close() and exc_type is None:\n            raise CleanupFailed()\n\n    def local(self):\n        return _current_build_context.with_value(self)\n\n    def close(self):\n        any_failed = False\n        for task in self.tasks:\n            try:\n                task()\n            except BaseException:\n                any_failed = True\n                report(traceback.format_exc())\n        return any_failed\n\n\ndef cleanup(teardown):\n    \"\"\"Register a function to be called when the current test has finished\n    executing. Any exceptions thrown in teardown will be printed but not\n    rethrown.\n\n    Inside a test this isn't very interesting, because you can just use\n    a finally block, but note that you can use this inside map, flatmap,\n    etc. in order to e.g. insist that a value is closed at the end.\n    \"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            u'Cannot register cleanup outside of build context')\n    context.tasks.append(teardown)\n\n\ndef note(value):\n    # type: (AnyStr) -> None\n    \"\"\"Report this value in the final execution.\"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            'Cannot make notes outside of a test')\n    context.notes.append(value)\n    if context.is_final or settings.default.verbosity >= Verbosity.verbose:\n        report(value)\n\n\ndef event(value):\n    # type: (AnyStr) -> None\n    \"\"\"Record an event that occurred this test. Statistics on number of test\n    runs with each event will be reported at the end if you run Hypothesis in\n    statistics reporting mode.\n\n    Events should be strings or convertible to them.\n    \"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            'Cannot make record events outside of a test')\n\n    if context.data is not None:\n        context.data.note_event(value)\n", "path": "hypothesis-python/src/hypothesis/control.py"}], "after_files": [{"content": "# coding=utf-8\n#\n# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis-python\n#\n# Most of this work is copyright (C) 2013-2018 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# CONTRIBUTING.rst for a full list of people who may hold copyright, and\n# consult the git log if you need to determine who owns an individual\n# contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at http://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom __future__ import division, print_function, absolute_import\n\nimport logging\nimport traceback\n\nfrom hypothesis import Verbosity, settings\nfrom hypothesis.errors import CleanupFailed, InvalidArgument, \\\n    UnsatisfiedAssumption\nfrom hypothesis.reporting import report\nfrom hypothesis.utils.dynamicvariables import DynamicVariable\n\nif False:\n    from typing import Any, AnyStr  # noqa\n\n\ndef reject():\n    raise UnsatisfiedAssumption()\n\n\ndef assume(condition):\n    # type: (Any) -> bool\n    \"\"\"Calling ``assume`` is like an :ref:`assert <python:assert>` that marks\n    the example as bad, rather than failing the test.\n\n    This allows you to specify properties that you *assume* will be\n    true, and let Hypothesis try to avoid similar examples in future.\n    \"\"\"\n    if not condition:\n        raise UnsatisfiedAssumption()\n    return True\n\n\n_current_build_context = DynamicVariable(None)\n\n\ndef current_build_context():\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            u'No build context registered')\n    return context\n\n\nclass BuildContext(object):\n\n    def __init__(self, data, is_final=False, close_on_capture=True):\n        self.data = data\n        self.tasks = []\n        self.is_final = is_final\n        self.close_on_capture = close_on_capture\n        self.close_on_del = False\n        self.notes = []\n        self.original_logging_disable = logging.NOTSET\n\n    def __enter__(self):\n        if not self.is_final:\n            self.original_logging_disable = logging.root.manager.disable\n            logging.disable(logging.CRITICAL)\n        self.assign_variable = _current_build_context.with_value(self)\n        self.assign_variable.__enter__()\n        return self\n\n    def __exit__(self, exc_type, exc_value, tb):\n        self.assign_variable.__exit__(exc_type, exc_value, tb)\n        if not self.is_final:\n            logging.disable(self.original_logging_disable)\n        if self.close() and exc_type is None:\n            raise CleanupFailed()\n\n    def local(self):\n        return _current_build_context.with_value(self)\n\n    def close(self):\n        any_failed = False\n        for task in self.tasks:\n            try:\n                task()\n            except BaseException:\n                any_failed = True\n                report(traceback.format_exc())\n        return any_failed\n\n\ndef cleanup(teardown):\n    \"\"\"Register a function to be called when the current test has finished\n    executing. Any exceptions thrown in teardown will be printed but not\n    rethrown.\n\n    Inside a test this isn't very interesting, because you can just use\n    a finally block, but note that you can use this inside map, flatmap,\n    etc. in order to e.g. insist that a value is closed at the end.\n    \"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            u'Cannot register cleanup outside of build context')\n    context.tasks.append(teardown)\n\n\ndef note(value):\n    # type: (AnyStr) -> None\n    \"\"\"Report this value in the final execution.\"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            'Cannot make notes outside of a test')\n    context.notes.append(value)\n    if context.is_final or settings.default.verbosity >= Verbosity.verbose:\n        report(value)\n\n\ndef event(value):\n    # type: (AnyStr) -> None\n    \"\"\"Record an event that occurred this test. Statistics on number of test\n    runs with each event will be reported at the end if you run Hypothesis in\n    statistics reporting mode.\n\n    Events should be strings or convertible to them.\n    \"\"\"\n    context = _current_build_context.value\n    if context is None:\n        raise InvalidArgument(\n            'Cannot make record events outside of a test')\n\n    if context.data is not None:\n        context.data.note_event(value)\n", "path": "hypothesis-python/src/hypothesis/control.py"}]}