We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pytest function scoped fixtures should run once per example, not once per test
Because of the way Hypothesis just exposes a single test function, pytest just runs its fixtures once for that function.

This is a long running problem with Hypothesis's interaction with pytest and there is [an open bug about it on the pytest side too](https://github.com/pytest-dev/pytest/issues/916).

Fixing this is tricky. The [fixtures-integration](https://github.com/HypothesisWorks/hypothesis-python/tree/fixtures-integration) branch has a partial prototype which makes _some_ progress towards making it work, but it's very far from complete and has a number of issues which are likely to need substantial work to fix.

I [am currently seeking funding to work on this ticket](http://hypothesis.works/articles/pytest-integration-sponsorship/) and it is unlikely to make much progress without said funding.


--- 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/extra/pytestplugin.py`
Content:
```
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Most of this work is copyright (C) 2013-2020 David R. MacIver
5 # (david@drmaciver.com), but it contains contributions by others. See
6 # CONTRIBUTING.rst for a full list of people who may hold copyright, and
7 # consult the git log if you need to determine who owns an individual
8 # contribution.
9 #
10 # This Source Code Form is subject to the terms of the Mozilla Public License,
11 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
12 # obtain one at https://mozilla.org/MPL/2.0/.
13 #
14 # END HEADER
15 
16 from distutils.version import LooseVersion
17 
18 import pytest
19 
20 from hypothesis import Verbosity, core, settings
21 from hypothesis.errors import InvalidArgument
22 from hypothesis.internal.detection import is_hypothesis_test
23 from hypothesis.reporting import default as default_reporter, with_reporter
24 from hypothesis.statistics import collector
25 
26 LOAD_PROFILE_OPTION = "--hypothesis-profile"
27 VERBOSITY_OPTION = "--hypothesis-verbosity"
28 PRINT_STATISTICS_OPTION = "--hypothesis-show-statistics"
29 SEED_OPTION = "--hypothesis-seed"
30 
31 
32 class StoringReporter:
33     def __init__(self, config):
34         self.config = config
35         self.results = []
36 
37     def __call__(self, msg):
38         if self.config.getoption("capture", "fd") == "no":
39             default_reporter(msg)
40         if not isinstance(msg, str):
41             msg = repr(msg)
42         self.results.append(msg)
43 
44 
45 if LooseVersion(pytest.__version__) < "4.3":  # pragma: no cover
46     import warnings
47     from hypothesis.errors import HypothesisWarning
48 
49     PYTEST_TOO_OLD_MESSAGE = """
50         You are using Pytest version %s.  Hypothesis tests work with any test
51         runner, but our Pytest plugin requires Pytest  4.3 or newer.
52         Note that the Pytest developers no longer support this version either!
53         Disabling the Hypothesis pytest plugin...
54     """
55     warnings.warn(PYTEST_TOO_OLD_MESSAGE % (pytest.__version__,), HypothesisWarning)
56 
57 else:
58 
59     def pytest_addoption(parser):
60         group = parser.getgroup("hypothesis", "Hypothesis")
61         group.addoption(
62             LOAD_PROFILE_OPTION,
63             action="store",
64             help="Load in a registered hypothesis.settings profile",
65         )
66         group.addoption(
67             VERBOSITY_OPTION,
68             action="store",
69             choices=[opt.name for opt in Verbosity],
70             help="Override profile with verbosity setting specified",
71         )
72         group.addoption(
73             PRINT_STATISTICS_OPTION,
74             action="store_true",
75             help="Configure when statistics are printed",
76             default=False,
77         )
78         group.addoption(
79             SEED_OPTION,
80             action="store",
81             help="Set a seed to use for all Hypothesis tests",
82         )
83 
84     def pytest_report_header(config):
85         profile = config.getoption(LOAD_PROFILE_OPTION)
86         if not profile:
87             profile = settings._current_profile
88         settings_str = settings.get_profile(profile).show_changed()
89         if settings_str != "":
90             settings_str = " -> %s" % (settings_str)
91         if (
92             config.option.verbose >= 1
93             or settings.default.verbosity >= Verbosity.verbose
94         ):
95             return "hypothesis profile %r%s" % (profile, settings_str)
96 
97     def pytest_configure(config):
98         core.running_under_pytest = True
99         profile = config.getoption(LOAD_PROFILE_OPTION)
100         if profile:
101             settings.load_profile(profile)
102         verbosity_name = config.getoption(VERBOSITY_OPTION)
103         if verbosity_name:
104             verbosity_value = Verbosity[verbosity_name]
105             profile_name = "%s-with-%s-verbosity" % (
106                 settings._current_profile,
107                 verbosity_name,
108             )
109             # register_profile creates a new profile, exactly like the current one,
110             # with the extra values given (in this case 'verbosity')
111             settings.register_profile(profile_name, verbosity=verbosity_value)
112             settings.load_profile(profile_name)
113         seed = config.getoption(SEED_OPTION)
114         if seed is not None:
115             try:
116                 seed = int(seed)
117             except ValueError:
118                 pass
119             core.global_force_seed = seed
120         config.addinivalue_line("markers", "hypothesis: Tests which use hypothesis.")
121 
122     @pytest.hookimpl(hookwrapper=True)
123     def pytest_runtest_call(item):
124         if not hasattr(item, "obj"):
125             yield
126         elif not is_hypothesis_test(item.obj):
127             # If @given was not applied, check whether other hypothesis
128             # decorators were applied, and raise an error if they were.
129             if getattr(item.obj, "is_hypothesis_strategy_function", False):
130                 raise InvalidArgument(
131                     "%s is a function that returns a Hypothesis strategy, but pytest "
132                     "has collected it as a test function.  This is useless as the "
133                     "function body will never be executed.  To define a test "
134                     "function, use @given instead of @composite." % (item.nodeid,)
135                 )
136             message = "Using `@%s` on a test without `@given` is completely pointless."
137             for name, attribute in [
138                 ("example", "hypothesis_explicit_examples"),
139                 ("seed", "_hypothesis_internal_use_seed"),
140                 ("settings", "_hypothesis_internal_settings_applied"),
141                 ("reproduce_example", "_hypothesis_internal_use_reproduce_failure"),
142             ]:
143                 if hasattr(item.obj, attribute):
144                     raise InvalidArgument(message % (name,))
145             yield
146         else:
147             if item.get_closest_marker("parametrize") is not None:
148                 # Give every parametrized test invocation a unique database key
149                 key = item.nodeid.encode("utf-8")
150                 item.obj.hypothesis.inner_test._hypothesis_internal_add_digest = key
151 
152             store = StoringReporter(item.config)
153 
154             def note_statistics(stats):
155                 lines = [item.nodeid + ":", ""] + stats.get_description() + [""]
156                 item.hypothesis_statistics = lines
157 
158             with collector.with_value(note_statistics):
159                 with with_reporter(store):
160                     yield
161             if store.results:
162                 item.hypothesis_report_information = list(store.results)
163 
164     @pytest.hookimpl(hookwrapper=True)
165     def pytest_runtest_makereport(item, call):
166         report = (yield).get_result()
167         if hasattr(item, "hypothesis_report_information"):
168             report.sections.append(
169                 ("Hypothesis", "\n".join(item.hypothesis_report_information))
170             )
171         if hasattr(item, "hypothesis_statistics") and report.when == "teardown":
172             val = ("hypothesis-stats", item.hypothesis_statistics)
173             report.user_properties.append(val)
174 
175     def pytest_terminal_summary(terminalreporter):
176         if not terminalreporter.config.getoption(PRINT_STATISTICS_OPTION):
177             return
178         terminalreporter.section("Hypothesis Statistics")
179         # terminalreporter.stats is a dict, where the empty string appears to
180         # always be the key for a list of _pytest.reports.TestReport objects
181         # (where we stored the statistics data in pytest_runtest_makereport above)
182         for test_report in terminalreporter.stats.get("", []):
183             for name, lines in test_report.user_properties:
184                 if name == "hypothesis-stats" and test_report.when == "teardown":
185                     for li in lines:
186                         terminalreporter.write_line(li)
187 
188     def pytest_collection_modifyitems(items):
189         for item in items:
190             if isinstance(item, pytest.Function) and is_hypothesis_test(item.obj):
191                 item.add_marker("hypothesis")
192 
193 
194 def load():
195     """Required for `pluggy` to load a plugin from setuptools entrypoints."""
196
```
--- 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/extra/pytestplugin.py b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
--- a/hypothesis-python/src/hypothesis/extra/pytestplugin.py
+++ b/hypothesis-python/src/hypothesis/extra/pytestplugin.py
@@ -14,10 +14,12 @@
 # END HEADER
 
 from distutils.version import LooseVersion
+from inspect import signature
 
 import pytest
 
 from hypothesis import Verbosity, core, settings
+from hypothesis._settings import note_deprecation
 from hypothesis.errors import InvalidArgument
 from hypothesis.internal.detection import is_hypothesis_test
 from hypothesis.reporting import default as default_reporter, with_reporter
@@ -144,6 +146,25 @@
                     raise InvalidArgument(message % (name,))
             yield
         else:
+            # Warn about function-scoped fixtures, excluding autouse fixtures because
+            # the advice is probably not actionable and the status quo seems OK...
+            # See https://github.com/HypothesisWorks/hypothesis/issues/377 for detail.
+            argnames = None
+            for fx_defs in item._request._fixturemanager.getfixtureinfo(
+                node=item, func=item.function, cls=None
+            ).name2fixturedefs.values():
+                if argnames is None:
+                    argnames = frozenset(signature(item.function).parameters)
+                for fx in fx_defs:
+                    if fx.scope == "function" and fx.argname in argnames:
+                        note_deprecation(
+                            "%s uses the %r fixture, but function-scoped fixtures "
+                            "should not be used with @given(...) tests, because "
+                            "fixtures are not reset between generated examples!"
+                            % (item.nodeid, fx.argname),
+                            since="RELEASEDAY",
+                        )
+
             if item.get_closest_marker("parametrize") is not None:
                 # Give every parametrized test invocation a unique database key
                 key = item.nodeid.encode("utf-8")

{"golden_diff": "diff --git a/hypothesis-python/src/hypothesis/extra/pytestplugin.py b/hypothesis-python/src/hypothesis/extra/pytestplugin.py\n--- a/hypothesis-python/src/hypothesis/extra/pytestplugin.py\n+++ b/hypothesis-python/src/hypothesis/extra/pytestplugin.py\n@@ -14,10 +14,12 @@\n # END HEADER\n \n from distutils.version import LooseVersion\n+from inspect import signature\n \n import pytest\n \n from hypothesis import Verbosity, core, settings\n+from hypothesis._settings import note_deprecation\n from hypothesis.errors import InvalidArgument\n from hypothesis.internal.detection import is_hypothesis_test\n from hypothesis.reporting import default as default_reporter, with_reporter\n@@ -144,6 +146,25 @@\n                     raise InvalidArgument(message % (name,))\n             yield\n         else:\n+            # Warn about function-scoped fixtures, excluding autouse fixtures because\n+            # the advice is probably not actionable and the status quo seems OK...\n+            # See https://github.com/HypothesisWorks/hypothesis/issues/377 for detail.\n+            argnames = None\n+            for fx_defs in item._request._fixturemanager.getfixtureinfo(\n+                node=item, func=item.function, cls=None\n+            ).name2fixturedefs.values():\n+                if argnames is None:\n+                    argnames = frozenset(signature(item.function).parameters)\n+                for fx in fx_defs:\n+                    if fx.scope == \"function\" and fx.argname in argnames:\n+                        note_deprecation(\n+                            \"%s uses the %r fixture, but function-scoped fixtures \"\n+                            \"should not be used with @given(...) tests, because \"\n+                            \"fixtures are not reset between generated examples!\"\n+                            % (item.nodeid, fx.argname),\n+                            since=\"RELEASEDAY\",\n+                        )\n+\n             if item.get_closest_marker(\"parametrize\") is not None:\n                 # Give every parametrized test invocation a unique database key\n                 key = item.nodeid.encode(\"utf-8\")\n", "issue": "pytest function scoped fixtures should run once per example, not once per test\nBecause of the way Hypothesis just exposes a single test function, pytest just runs its fixtures once for that function.\n\nThis is a long running problem with Hypothesis's interaction with pytest and there is [an open bug about it on the pytest side too](https://github.com/pytest-dev/pytest/issues/916).\n\nFixing this is tricky. The [fixtures-integration](https://github.com/HypothesisWorks/hypothesis-python/tree/fixtures-integration) branch has a partial prototype which makes _some_ progress towards making it work, but it's very far from complete and has a number of issues which are likely to need substantial work to fix.\n\nI [am currently seeking funding to work on this ticket](http://hypothesis.works/articles/pytest-integration-sponsorship/) and it is unlikely to make much progress without said funding.\n\n", "before_files": [{"content": "# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis/\n#\n# Most of this work is copyright (C) 2013-2020 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 https://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom distutils.version import LooseVersion\n\nimport pytest\n\nfrom hypothesis import Verbosity, core, settings\nfrom hypothesis.errors import InvalidArgument\nfrom hypothesis.internal.detection import is_hypothesis_test\nfrom hypothesis.reporting import default as default_reporter, with_reporter\nfrom hypothesis.statistics import collector\n\nLOAD_PROFILE_OPTION = \"--hypothesis-profile\"\nVERBOSITY_OPTION = \"--hypothesis-verbosity\"\nPRINT_STATISTICS_OPTION = \"--hypothesis-show-statistics\"\nSEED_OPTION = \"--hypothesis-seed\"\n\n\nclass StoringReporter:\n    def __init__(self, config):\n        self.config = config\n        self.results = []\n\n    def __call__(self, msg):\n        if self.config.getoption(\"capture\", \"fd\") == \"no\":\n            default_reporter(msg)\n        if not isinstance(msg, str):\n            msg = repr(msg)\n        self.results.append(msg)\n\n\nif LooseVersion(pytest.__version__) < \"4.3\":  # pragma: no cover\n    import warnings\n    from hypothesis.errors import HypothesisWarning\n\n    PYTEST_TOO_OLD_MESSAGE = \"\"\"\n        You are using Pytest version %s.  Hypothesis tests work with any test\n        runner, but our Pytest plugin requires Pytest  4.3 or newer.\n        Note that the Pytest developers no longer support this version either!\n        Disabling the Hypothesis pytest plugin...\n    \"\"\"\n    warnings.warn(PYTEST_TOO_OLD_MESSAGE % (pytest.__version__,), HypothesisWarning)\n\nelse:\n\n    def pytest_addoption(parser):\n        group = parser.getgroup(\"hypothesis\", \"Hypothesis\")\n        group.addoption(\n            LOAD_PROFILE_OPTION,\n            action=\"store\",\n            help=\"Load in a registered hypothesis.settings profile\",\n        )\n        group.addoption(\n            VERBOSITY_OPTION,\n            action=\"store\",\n            choices=[opt.name for opt in Verbosity],\n            help=\"Override profile with verbosity setting specified\",\n        )\n        group.addoption(\n            PRINT_STATISTICS_OPTION,\n            action=\"store_true\",\n            help=\"Configure when statistics are printed\",\n            default=False,\n        )\n        group.addoption(\n            SEED_OPTION,\n            action=\"store\",\n            help=\"Set a seed to use for all Hypothesis tests\",\n        )\n\n    def pytest_report_header(config):\n        profile = config.getoption(LOAD_PROFILE_OPTION)\n        if not profile:\n            profile = settings._current_profile\n        settings_str = settings.get_profile(profile).show_changed()\n        if settings_str != \"\":\n            settings_str = \" -> %s\" % (settings_str)\n        if (\n            config.option.verbose >= 1\n            or settings.default.verbosity >= Verbosity.verbose\n        ):\n            return \"hypothesis profile %r%s\" % (profile, settings_str)\n\n    def pytest_configure(config):\n        core.running_under_pytest = True\n        profile = config.getoption(LOAD_PROFILE_OPTION)\n        if profile:\n            settings.load_profile(profile)\n        verbosity_name = config.getoption(VERBOSITY_OPTION)\n        if verbosity_name:\n            verbosity_value = Verbosity[verbosity_name]\n            profile_name = \"%s-with-%s-verbosity\" % (\n                settings._current_profile,\n                verbosity_name,\n            )\n            # register_profile creates a new profile, exactly like the current one,\n            # with the extra values given (in this case 'verbosity')\n            settings.register_profile(profile_name, verbosity=verbosity_value)\n            settings.load_profile(profile_name)\n        seed = config.getoption(SEED_OPTION)\n        if seed is not None:\n            try:\n                seed = int(seed)\n            except ValueError:\n                pass\n            core.global_force_seed = seed\n        config.addinivalue_line(\"markers\", \"hypothesis: Tests which use hypothesis.\")\n\n    @pytest.hookimpl(hookwrapper=True)\n    def pytest_runtest_call(item):\n        if not hasattr(item, \"obj\"):\n            yield\n        elif not is_hypothesis_test(item.obj):\n            # If @given was not applied, check whether other hypothesis\n            # decorators were applied, and raise an error if they were.\n            if getattr(item.obj, \"is_hypothesis_strategy_function\", False):\n                raise InvalidArgument(\n                    \"%s is a function that returns a Hypothesis strategy, but pytest \"\n                    \"has collected it as a test function.  This is useless as the \"\n                    \"function body will never be executed.  To define a test \"\n                    \"function, use @given instead of @composite.\" % (item.nodeid,)\n                )\n            message = \"Using `@%s` on a test without `@given` is completely pointless.\"\n            for name, attribute in [\n                (\"example\", \"hypothesis_explicit_examples\"),\n                (\"seed\", \"_hypothesis_internal_use_seed\"),\n                (\"settings\", \"_hypothesis_internal_settings_applied\"),\n                (\"reproduce_example\", \"_hypothesis_internal_use_reproduce_failure\"),\n            ]:\n                if hasattr(item.obj, attribute):\n                    raise InvalidArgument(message % (name,))\n            yield\n        else:\n            if item.get_closest_marker(\"parametrize\") is not None:\n                # Give every parametrized test invocation a unique database key\n                key = item.nodeid.encode(\"utf-8\")\n                item.obj.hypothesis.inner_test._hypothesis_internal_add_digest = key\n\n            store = StoringReporter(item.config)\n\n            def note_statistics(stats):\n                lines = [item.nodeid + \":\", \"\"] + stats.get_description() + [\"\"]\n                item.hypothesis_statistics = lines\n\n            with collector.with_value(note_statistics):\n                with with_reporter(store):\n                    yield\n            if store.results:\n                item.hypothesis_report_information = list(store.results)\n\n    @pytest.hookimpl(hookwrapper=True)\n    def pytest_runtest_makereport(item, call):\n        report = (yield).get_result()\n        if hasattr(item, \"hypothesis_report_information\"):\n            report.sections.append(\n                (\"Hypothesis\", \"\\n\".join(item.hypothesis_report_information))\n            )\n        if hasattr(item, \"hypothesis_statistics\") and report.when == \"teardown\":\n            val = (\"hypothesis-stats\", item.hypothesis_statistics)\n            report.user_properties.append(val)\n\n    def pytest_terminal_summary(terminalreporter):\n        if not terminalreporter.config.getoption(PRINT_STATISTICS_OPTION):\n            return\n        terminalreporter.section(\"Hypothesis Statistics\")\n        # terminalreporter.stats is a dict, where the empty string appears to\n        # always be the key for a list of _pytest.reports.TestReport objects\n        # (where we stored the statistics data in pytest_runtest_makereport above)\n        for test_report in terminalreporter.stats.get(\"\", []):\n            for name, lines in test_report.user_properties:\n                if name == \"hypothesis-stats\" and test_report.when == \"teardown\":\n                    for li in lines:\n                        terminalreporter.write_line(li)\n\n    def pytest_collection_modifyitems(items):\n        for item in items:\n            if isinstance(item, pytest.Function) and is_hypothesis_test(item.obj):\n                item.add_marker(\"hypothesis\")\n\n\ndef load():\n    \"\"\"Required for `pluggy` to load a plugin from setuptools entrypoints.\"\"\"\n", "path": "hypothesis-python/src/hypothesis/extra/pytestplugin.py"}], "after_files": [{"content": "# This file is part of Hypothesis, which may be found at\n# https://github.com/HypothesisWorks/hypothesis/\n#\n# Most of this work is copyright (C) 2013-2020 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 https://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom distutils.version import LooseVersion\nfrom inspect import signature\n\nimport pytest\n\nfrom hypothesis import Verbosity, core, settings\nfrom hypothesis._settings import note_deprecation\nfrom hypothesis.errors import InvalidArgument\nfrom hypothesis.internal.detection import is_hypothesis_test\nfrom hypothesis.reporting import default as default_reporter, with_reporter\nfrom hypothesis.statistics import collector\n\nLOAD_PROFILE_OPTION = \"--hypothesis-profile\"\nVERBOSITY_OPTION = \"--hypothesis-verbosity\"\nPRINT_STATISTICS_OPTION = \"--hypothesis-show-statistics\"\nSEED_OPTION = \"--hypothesis-seed\"\n\n\nclass StoringReporter:\n    def __init__(self, config):\n        self.config = config\n        self.results = []\n\n    def __call__(self, msg):\n        if self.config.getoption(\"capture\", \"fd\") == \"no\":\n            default_reporter(msg)\n        if not isinstance(msg, str):\n            msg = repr(msg)\n        self.results.append(msg)\n\n\nif LooseVersion(pytest.__version__) < \"4.3\":  # pragma: no cover\n    import warnings\n    from hypothesis.errors import HypothesisWarning\n\n    PYTEST_TOO_OLD_MESSAGE = \"\"\"\n        You are using Pytest version %s.  Hypothesis tests work with any test\n        runner, but our Pytest plugin requires Pytest  4.3 or newer.\n        Note that the Pytest developers no longer support this version either!\n        Disabling the Hypothesis pytest plugin...\n    \"\"\"\n    warnings.warn(PYTEST_TOO_OLD_MESSAGE % (pytest.__version__,), HypothesisWarning)\n\nelse:\n\n    def pytest_addoption(parser):\n        group = parser.getgroup(\"hypothesis\", \"Hypothesis\")\n        group.addoption(\n            LOAD_PROFILE_OPTION,\n            action=\"store\",\n            help=\"Load in a registered hypothesis.settings profile\",\n        )\n        group.addoption(\n            VERBOSITY_OPTION,\n            action=\"store\",\n            choices=[opt.name for opt in Verbosity],\n            help=\"Override profile with verbosity setting specified\",\n        )\n        group.addoption(\n            PRINT_STATISTICS_OPTION,\n            action=\"store_true\",\n            help=\"Configure when statistics are printed\",\n            default=False,\n        )\n        group.addoption(\n            SEED_OPTION,\n            action=\"store\",\n            help=\"Set a seed to use for all Hypothesis tests\",\n        )\n\n    def pytest_report_header(config):\n        profile = config.getoption(LOAD_PROFILE_OPTION)\n        if not profile:\n            profile = settings._current_profile\n        settings_str = settings.get_profile(profile).show_changed()\n        if settings_str != \"\":\n            settings_str = \" -> %s\" % (settings_str)\n        if (\n            config.option.verbose >= 1\n            or settings.default.verbosity >= Verbosity.verbose\n        ):\n            return \"hypothesis profile %r%s\" % (profile, settings_str)\n\n    def pytest_configure(config):\n        core.running_under_pytest = True\n        profile = config.getoption(LOAD_PROFILE_OPTION)\n        if profile:\n            settings.load_profile(profile)\n        verbosity_name = config.getoption(VERBOSITY_OPTION)\n        if verbosity_name:\n            verbosity_value = Verbosity[verbosity_name]\n            profile_name = \"%s-with-%s-verbosity\" % (\n                settings._current_profile,\n                verbosity_name,\n            )\n            # register_profile creates a new profile, exactly like the current one,\n            # with the extra values given (in this case 'verbosity')\n            settings.register_profile(profile_name, verbosity=verbosity_value)\n            settings.load_profile(profile_name)\n        seed = config.getoption(SEED_OPTION)\n        if seed is not None:\n            try:\n                seed = int(seed)\n            except ValueError:\n                pass\n            core.global_force_seed = seed\n        config.addinivalue_line(\"markers\", \"hypothesis: Tests which use hypothesis.\")\n\n    @pytest.hookimpl(hookwrapper=True)\n    def pytest_runtest_call(item):\n        if not hasattr(item, \"obj\"):\n            yield\n        elif not is_hypothesis_test(item.obj):\n            # If @given was not applied, check whether other hypothesis\n            # decorators were applied, and raise an error if they were.\n            if getattr(item.obj, \"is_hypothesis_strategy_function\", False):\n                raise InvalidArgument(\n                    \"%s is a function that returns a Hypothesis strategy, but pytest \"\n                    \"has collected it as a test function.  This is useless as the \"\n                    \"function body will never be executed.  To define a test \"\n                    \"function, use @given instead of @composite.\" % (item.nodeid,)\n                )\n            message = \"Using `@%s` on a test without `@given` is completely pointless.\"\n            for name, attribute in [\n                (\"example\", \"hypothesis_explicit_examples\"),\n                (\"seed\", \"_hypothesis_internal_use_seed\"),\n                (\"settings\", \"_hypothesis_internal_settings_applied\"),\n                (\"reproduce_example\", \"_hypothesis_internal_use_reproduce_failure\"),\n            ]:\n                if hasattr(item.obj, attribute):\n                    raise InvalidArgument(message % (name,))\n            yield\n        else:\n            # Warn about function-scoped fixtures, excluding autouse fixtures because\n            # the advice is probably not actionable and the status quo seems OK...\n            # See https://github.com/HypothesisWorks/hypothesis/issues/377 for detail.\n            argnames = None\n            for fx_defs in item._request._fixturemanager.getfixtureinfo(\n                node=item, func=item.function, cls=None\n            ).name2fixturedefs.values():\n                if argnames is None:\n                    argnames = frozenset(signature(item.function).parameters)\n                for fx in fx_defs:\n                    if fx.scope == \"function\" and fx.argname in argnames:\n                        note_deprecation(\n                            \"%s uses the %r fixture, but function-scoped fixtures \"\n                            \"should not be used with @given(...) tests, because \"\n                            \"fixtures are not reset between generated examples!\"\n                            % (item.nodeid, fx.argname),\n                            since=\"RELEASEDAY\",\n                        )\n\n            if item.get_closest_marker(\"parametrize\") is not None:\n                # Give every parametrized test invocation a unique database key\n                key = item.nodeid.encode(\"utf-8\")\n                item.obj.hypothesis.inner_test._hypothesis_internal_add_digest = key\n\n            store = StoringReporter(item.config)\n\n            def note_statistics(stats):\n                lines = [item.nodeid + \":\", \"\"] + stats.get_description() + [\"\"]\n                item.hypothesis_statistics = lines\n\n            with collector.with_value(note_statistics):\n                with with_reporter(store):\n                    yield\n            if store.results:\n                item.hypothesis_report_information = list(store.results)\n\n    @pytest.hookimpl(hookwrapper=True)\n    def pytest_runtest_makereport(item, call):\n        report = (yield).get_result()\n        if hasattr(item, \"hypothesis_report_information\"):\n            report.sections.append(\n                (\"Hypothesis\", \"\\n\".join(item.hypothesis_report_information))\n            )\n        if hasattr(item, \"hypothesis_statistics\") and report.when == \"teardown\":\n            val = (\"hypothesis-stats\", item.hypothesis_statistics)\n            report.user_properties.append(val)\n\n    def pytest_terminal_summary(terminalreporter):\n        if not terminalreporter.config.getoption(PRINT_STATISTICS_OPTION):\n            return\n        terminalreporter.section(\"Hypothesis Statistics\")\n        # terminalreporter.stats is a dict, where the empty string appears to\n        # always be the key for a list of _pytest.reports.TestReport objects\n        # (where we stored the statistics data in pytest_runtest_makereport above)\n        for test_report in terminalreporter.stats.get(\"\", []):\n            for name, lines in test_report.user_properties:\n                if name == \"hypothesis-stats\" and test_report.when == \"teardown\":\n                    for li in lines:\n                        terminalreporter.write_line(li)\n\n    def pytest_collection_modifyitems(items):\n        for item in items:\n            if isinstance(item, pytest.Function) and is_hypothesis_test(item.obj):\n                item.add_marker(\"hypothesis\")\n\n\ndef load():\n    \"\"\"Required for `pluggy` to load a plugin from setuptools entrypoints.\"\"\"\n", "path": "hypothesis-python/src/hypothesis/extra/pytestplugin.py"}]}