prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Run tests with warnings as errors
  This is harder than it sounds, because practically everything in a Python stack emits warnings.  See #1124, #1149, and #1169 for previous work on this.
  
  One lead is to check whether we can put e.g. `,default:::setuptools,default:::pip` at the end of the [`PYTHONWARNINGS`](https://docs.python.org/3/using/cmdline.html#cmdoption-w) variable, which would exempt build-time dependencies (that we can't fix) from `=error,` at the front.  Unclear from the docs whether we can use one entry per package, or if it's one per file.
  
  Internally, we get a `ResourceWarning` from failing to close a [`branch-check` file](https://github.com/HypothesisWorks/hypothesis-python/blob/06a6ce681b8f13676ae2b674c559c413f0f3dbac/src/hypothesis/internal/coverage.py#L60) in the coverage job (fixable with a minor refactor to use `mode='a'`).  There are probably more warnings that we simply don't notice at the moment.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/hypothesis/internal/coverage.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 os
  21 import sys
  22 import json
  23 from contextlib import contextmanager
  24 
  25 from hypothesis.internal.reflection import proxies
  26 
  27 """
  28 This module implements a custom coverage system that records conditions and
  29 then validates that every condition has been seen to be both True and False
  30 during the execution of our tests.
  31 
  32 The only thing we use it for at present is our argument validation functions,
  33 where we assert that every validation function has been seen to both pass and
  34 fail in the course of testing.
  35 
  36 When not running with a magic environment variable set, this module disables
  37 itself and has essentially no overhead.
  38 """
  39 
  40 pretty_file_name_cache = {}
  41 
  42 
  43 def pretty_file_name(f):
  44     try:
  45         return pretty_file_name_cache[f]
  46     except KeyError:
  47         pass
  48 
  49     parts = f.split(os.path.sep)
  50     parts = parts[parts.index('hypothesis'):]
  51     result = os.path.sep.join(parts)
  52     pretty_file_name_cache[f] = result
  53     return result
  54 
  55 
  56 IN_COVERAGE_TESTS = os.getenv('HYPOTHESIS_INTERNAL_COVERAGE') == 'true'
  57 
  58 
  59 if IN_COVERAGE_TESTS:
  60     log = open('branch-check', 'w')
  61     written = set()
  62 
  63     def record_branch(name, value):
  64         key = (name, value)
  65         if key in written:
  66             return
  67         written.add(key)
  68         log.write(
  69             json.dumps({'name': name, 'value': value})
  70         )
  71         log.write('\n')
  72         log.flush()
  73 
  74     description_stack = []
  75 
  76     @contextmanager
  77     def check_block(name, depth):
  78         # We add an extra two callers to the stack: One for the contextmanager
  79         # function, one for our actual caller, so we want to go two extra
  80         # stack frames up.
  81         caller = sys._getframe(depth + 2)
  82         local_description = '%s at %s:%d' % (
  83             name,
  84             pretty_file_name(caller.f_code.co_filename),
  85             caller.f_lineno,
  86         )
  87         try:
  88             description_stack.append(local_description)
  89             description = ' in '.join(reversed(description_stack)) + ' passed'
  90             yield
  91             record_branch(description, True)
  92         except BaseException:
  93             record_branch(description, False)
  94             raise
  95         finally:
  96             description_stack.pop()
  97 
  98     @contextmanager
  99     def check(name):
  100         with check_block(name, 2):
  101             yield
  102 
  103     def check_function(f):
  104         @proxies(f)
  105         def accept(*args, **kwargs):
  106             # depth of 2 because of the proxy function calling us.
  107             with check_block(f.__name__, 2):
  108                 return f(*args, **kwargs)
  109         return accept
  110 else:
  111     def check_function(f):
  112         return f
  113 
  114     @contextmanager
  115     def check(name):
  116         yield
  117 
  118 
  119 class suppress_tracing(object):
  120     def __enter__(self):
  121         self.__original_trace = sys.gettrace()
  122         sys.settrace(None)
  123 
  124     def __exit__(self, exc_type, exc_value, traceback):
  125         sys.settrace(self.__original_trace)
  126
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/src/hypothesis/internal/coverage.py b/src/hypothesis/internal/coverage.py
  --- a/src/hypothesis/internal/coverage.py
  +++ b/src/hypothesis/internal/coverage.py
  @@ -57,7 +57,8 @@
   
   
   if IN_COVERAGE_TESTS:
  -    log = open('branch-check', 'w')
  +    with open('branch-check', 'w'):
  +        pass
       written = set()
   
       def record_branch(name, value):
  @@ -65,11 +66,8 @@
           if key in written:
               return
           written.add(key)
  -        log.write(
  -            json.dumps({'name': name, 'value': value})
  -        )
  -        log.write('\n')
  -        log.flush()
  +        with open('branch-check', 'a') as log:
  +            log.write(json.dumps({'name': name, 'value': value}) + '\n')
   
       description_stack = []
  
verification_info: {"golden_diff": "diff --git a/src/hypothesis/internal/coverage.py b/src/hypothesis/internal/coverage.py\n--- a/src/hypothesis/internal/coverage.py\n+++ b/src/hypothesis/internal/coverage.py\n@@ -57,7 +57,8 @@\n \n \n if IN_COVERAGE_TESTS:\n-    log = open('branch-check', 'w')\n+    with open('branch-check', 'w'):\n+        pass\n     written = set()\n \n     def record_branch(name, value):\n@@ -65,11 +66,8 @@\n         if key in written:\n             return\n         written.add(key)\n-        log.write(\n-            json.dumps({'name': name, 'value': value})\n-        )\n-        log.write('\\n')\n-        log.flush()\n+        with open('branch-check', 'a') as log:\n+            log.write(json.dumps({'name': name, 'value': value}) + '\\n')\n \n     description_stack = []\n", "issue": "Run tests with warnings as errors\nThis is harder than it sounds, because practically everything in a Python stack emits warnings.  See #1124, #1149, and #1169 for previous work on this.\r\n\r\nOne lead is to check whether we can put e.g. `,default:::setuptools,default:::pip` at the end of the [`PYTHONWARNINGS`](https://docs.python.org/3/using/cmdline.html#cmdoption-w) variable, which would exempt build-time dependencies (that we can't fix) from `=error,` at the front.  Unclear from the docs whether we can use one entry per package, or if it's one per file.\r\n\r\nInternally, we get a `ResourceWarning` from failing to close a [`branch-check` file](https://github.com/HypothesisWorks/hypothesis-python/blob/06a6ce681b8f13676ae2b674c559c413f0f3dbac/src/hypothesis/internal/coverage.py#L60) in the coverage job (fixable with a minor refactor to use `mode='a'`).  There are probably more warnings that we simply don't notice at the moment.\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 os\nimport sys\nimport json\nfrom contextlib import contextmanager\n\nfrom hypothesis.internal.reflection import proxies\n\n\"\"\"\nThis module implements a custom coverage system that records conditions and\nthen validates that every condition has been seen to be both True and False\nduring the execution of our tests.\n\nThe only thing we use it for at present is our argument validation functions,\nwhere we assert that every validation function has been seen to both pass and\nfail in the course of testing.\n\nWhen not running with a magic environment variable set, this module disables\nitself and has essentially no overhead.\n\"\"\"\n\npretty_file_name_cache = {}\n\n\ndef pretty_file_name(f):\n    try:\n        return pretty_file_name_cache[f]\n    except KeyError:\n        pass\n\n    parts = f.split(os.path.sep)\n    parts = parts[parts.index('hypothesis'):]\n    result = os.path.sep.join(parts)\n    pretty_file_name_cache[f] = result\n    return result\n\n\nIN_COVERAGE_TESTS = os.getenv('HYPOTHESIS_INTERNAL_COVERAGE') == 'true'\n\n\nif IN_COVERAGE_TESTS:\n    log = open('branch-check', 'w')\n    written = set()\n\n    def record_branch(name, value):\n        key = (name, value)\n        if key in written:\n            return\n        written.add(key)\n        log.write(\n            json.dumps({'name': name, 'value': value})\n        )\n        log.write('\\n')\n        log.flush()\n\n    description_stack = []\n\n    @contextmanager\n    def check_block(name, depth):\n        # We add an extra two callers to the stack: One for the contextmanager\n        # function, one for our actual caller, so we want to go two extra\n        # stack frames up.\n        caller = sys._getframe(depth + 2)\n        local_description = '%s at %s:%d' % (\n            name,\n            pretty_file_name(caller.f_code.co_filename),\n            caller.f_lineno,\n        )\n        try:\n            description_stack.append(local_description)\n            description = ' in '.join(reversed(description_stack)) + ' passed'\n            yield\n            record_branch(description, True)\n        except BaseException:\n            record_branch(description, False)\n            raise\n        finally:\n            description_stack.pop()\n\n    @contextmanager\n    def check(name):\n        with check_block(name, 2):\n            yield\n\n    def check_function(f):\n        @proxies(f)\n        def accept(*args, **kwargs):\n            # depth of 2 because of the proxy function calling us.\n            with check_block(f.__name__, 2):\n                return f(*args, **kwargs)\n        return accept\nelse:\n    def check_function(f):\n        return f\n\n    @contextmanager\n    def check(name):\n        yield\n\n\nclass suppress_tracing(object):\n    def __enter__(self):\n        self.__original_trace = sys.gettrace()\n        sys.settrace(None)\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        sys.settrace(self.__original_trace)\n", "path": "src/hypothesis/internal/coverage.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 os\nimport sys\nimport json\nfrom contextlib import contextmanager\n\nfrom hypothesis.internal.reflection import proxies\n\n\"\"\"\nThis module implements a custom coverage system that records conditions and\nthen validates that every condition has been seen to be both True and False\nduring the execution of our tests.\n\nThe only thing we use it for at present is our argument validation functions,\nwhere we assert that every validation function has been seen to both pass and\nfail in the course of testing.\n\nWhen not running with a magic environment variable set, this module disables\nitself and has essentially no overhead.\n\"\"\"\n\npretty_file_name_cache = {}\n\n\ndef pretty_file_name(f):\n    try:\n        return pretty_file_name_cache[f]\n    except KeyError:\n        pass\n\n    parts = f.split(os.path.sep)\n    parts = parts[parts.index('hypothesis'):]\n    result = os.path.sep.join(parts)\n    pretty_file_name_cache[f] = result\n    return result\n\n\nIN_COVERAGE_TESTS = os.getenv('HYPOTHESIS_INTERNAL_COVERAGE') == 'true'\n\n\nif IN_COVERAGE_TESTS:\n    with open('branch-check', 'w'):\n        pass\n    written = set()\n\n    def record_branch(name, value):\n        key = (name, value)\n        if key in written:\n            return\n        written.add(key)\n        with open('branch-check', 'a') as log:\n            log.write(json.dumps({'name': name, 'value': value}) + '\\n')\n\n    description_stack = []\n\n    @contextmanager\n    def check_block(name, depth):\n        # We add an extra two callers to the stack: One for the contextmanager\n        # function, one for our actual caller, so we want to go two extra\n        # stack frames up.\n        caller = sys._getframe(depth + 2)\n        local_description = '%s at %s:%d' % (\n            name,\n            pretty_file_name(caller.f_code.co_filename),\n            caller.f_lineno,\n        )\n        try:\n            description_stack.append(local_description)\n            description = ' in '.join(reversed(description_stack)) + ' passed'\n            yield\n            record_branch(description, True)\n        except BaseException:\n            record_branch(description, False)\n            raise\n        finally:\n            description_stack.pop()\n\n    @contextmanager\n    def check(name):\n        with check_block(name, 2):\n            yield\n\n    def check_function(f):\n        @proxies(f)\n        def accept(*args, **kwargs):\n            # depth of 2 because of the proxy function calling us.\n            with check_block(f.__name__, 2):\n                return f(*args, **kwargs)\n        return accept\nelse:\n    def check_function(f):\n        return f\n\n    @contextmanager\n    def check(name):\n        yield\n\n\nclass suppress_tracing(object):\n    def __enter__(self):\n        self.__original_trace = sys.gettrace()\n        sys.settrace(None)\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        sys.settrace(self.__original_trace)\n", "path": "src/hypothesis/internal/coverage.py"}]}