We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MAINT: ignore `.hypothesis/`
<!-- Please be sure you are following the instructions in the dev guidelines
http://www.numpy.org/devdocs/dev/development_workflow.html
-->

<!-- We'd appreciate it if your commit message is properly formatted
http://www.numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message
-->

I ran the test using `np.test()`. Then the `.hypothesis` directory was created. This seems to a byproduct of the test.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `numpy/conftest.py`
Content:
```
1 """
2 Pytest configuration and fixtures for the Numpy test suite.
3 """
4 import os
5 
6 import hypothesis
7 import pytest
8 import numpy
9 
10 from numpy.core._multiarray_tests import get_fpu_mode
11 
12 
13 _old_fpu_mode = None
14 _collect_results = {}
15 
16 # See https://hypothesis.readthedocs.io/en/latest/settings.html
17 hypothesis.settings.register_profile(
18     name="numpy-profile", deadline=None, print_blob=True,
19 )
20 hypothesis.settings.load_profile("numpy-profile")
21 
22 
23 def pytest_configure(config):
24     config.addinivalue_line("markers",
25         "valgrind_error: Tests that are known to error under valgrind.")
26     config.addinivalue_line("markers",
27         "leaks_references: Tests that are known to leak references.")
28     config.addinivalue_line("markers",
29         "slow: Tests that are very slow.")
30     config.addinivalue_line("markers",
31         "slow_pypy: Tests that are very slow on pypy.")
32 
33 
34 def pytest_addoption(parser):
35     parser.addoption("--available-memory", action="store", default=None,
36                      help=("Set amount of memory available for running the "
37                            "test suite. This can result to tests requiring "
38                            "especially large amounts of memory to be skipped. "
39                            "Equivalent to setting environment variable "
40                            "NPY_AVAILABLE_MEM. Default: determined"
41                            "automatically."))
42 
43 
44 def pytest_sessionstart(session):
45     available_mem = session.config.getoption('available_memory')
46     if available_mem is not None:
47         os.environ['NPY_AVAILABLE_MEM'] = available_mem
48 
49 
50 #FIXME when yield tests are gone.
51 @pytest.hookimpl()
52 def pytest_itemcollected(item):
53     """
54     Check FPU precision mode was not changed during test collection.
55 
56     The clumsy way we do it here is mainly necessary because numpy
57     still uses yield tests, which can execute code at test collection
58     time.
59     """
60     global _old_fpu_mode
61 
62     mode = get_fpu_mode()
63 
64     if _old_fpu_mode is None:
65         _old_fpu_mode = mode
66     elif mode != _old_fpu_mode:
67         _collect_results[item] = (_old_fpu_mode, mode)
68         _old_fpu_mode = mode
69 
70 
71 @pytest.fixture(scope="function", autouse=True)
72 def check_fpu_mode(request):
73     """
74     Check FPU precision mode was not changed during the test.
75     """
76     old_mode = get_fpu_mode()
77     yield
78     new_mode = get_fpu_mode()
79 
80     if old_mode != new_mode:
81         raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
82                              " during the test".format(old_mode, new_mode))
83 
84     collect_result = _collect_results.get(request.node)
85     if collect_result is not None:
86         old_mode, new_mode = collect_result
87         raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"
88                              " when collecting the test".format(old_mode,
89                                                                 new_mode))
90 
91 
92 @pytest.fixture(autouse=True)
93 def add_np(doctest_namespace):
94     doctest_namespace['np'] = numpy
95
```

Path: `numpy/_pytesttester.py`
Content:
```
1 """
2 Pytest test running.
3 
4 This module implements the ``test()`` function for NumPy modules. The usual
5 boiler plate for doing that is to put the following in the module
6 ``__init__.py`` file::
7 
8     from numpy._pytesttester import PytestTester
9     test = PytestTester(__name__).test
10     del PytestTester
11 
12 
13 Warnings filtering and other runtime settings should be dealt with in the
14 ``pytest.ini`` file in the numpy repo root. The behavior of the test depends on
15 whether or not that file is found as follows:
16 
17 * ``pytest.ini`` is present (develop mode)
18     All warnings except those explicitly filtered out are raised as error.
19 * ``pytest.ini`` is absent (release mode)
20     DeprecationWarnings and PendingDeprecationWarnings are ignored, other
21     warnings are passed through.
22 
23 In practice, tests run from the numpy repo are run in develop mode. That
24 includes the standard ``python runtests.py`` invocation.
25 
26 This module is imported by every numpy subpackage, so lies at the top level to
27 simplify circular import issues. For the same reason, it contains no numpy
28 imports at module scope, instead importing numpy within function calls.
29 """
30 import sys
31 import os
32 
33 __all__ = ['PytestTester']
34 
35 
36 
37 def _show_numpy_info():
38     from numpy.core._multiarray_umath import (
39         __cpu_features__, __cpu_baseline__, __cpu_dispatch__
40     )
41     import numpy as np
42 
43     print("NumPy version %s" % np.__version__)
44     relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
45     print("NumPy relaxed strides checking option:", relaxed_strides)
46 
47     if len(__cpu_baseline__) == 0 and len(__cpu_dispatch__) == 0:
48         enabled_features = "nothing enabled"
49     else:
50         enabled_features = ' '.join(__cpu_baseline__)
51         for feature in __cpu_dispatch__:
52             if __cpu_features__[feature]:
53                 enabled_features += " %s*" % feature
54             else:
55                 enabled_features += " %s?" % feature
56     print("NumPy CPU features:", enabled_features)
57 
58 
59 
60 class PytestTester:
61     """
62     Pytest test runner.
63 
64     A test function is typically added to a package's __init__.py like so::
65 
66       from numpy._pytesttester import PytestTester
67       test = PytestTester(__name__).test
68       del PytestTester
69 
70     Calling this test function finds and runs all tests associated with the
71     module and all its sub-modules.
72 
73     Attributes
74     ----------
75     module_name : str
76         Full path to the package to test.
77 
78     Parameters
79     ----------
80     module_name : module name
81         The name of the module to test.
82 
83     Notes
84     -----
85     Unlike the previous ``nose``-based implementation, this class is not
86     publicly exposed as it performs some ``numpy``-specific warning
87     suppression.
88 
89     """
90     def __init__(self, module_name):
91         self.module_name = module_name
92 
93     def __call__(self, label='fast', verbose=1, extra_argv=None,
94                  doctests=False, coverage=False, durations=-1, tests=None):
95         """
96         Run tests for module using pytest.
97 
98         Parameters
99         ----------
100         label : {'fast', 'full'}, optional
101             Identifies the tests to run. When set to 'fast', tests decorated
102             with `pytest.mark.slow` are skipped, when 'full', the slow marker
103             is ignored.
104         verbose : int, optional
105             Verbosity value for test outputs, in the range 1-3. Default is 1.
106         extra_argv : list, optional
107             List with any extra arguments to pass to pytests.
108         doctests : bool, optional
109             .. note:: Not supported
110         coverage : bool, optional
111             If True, report coverage of NumPy code. Default is False.
112             Requires installation of (pip) pytest-cov.
113         durations : int, optional
114             If < 0, do nothing, If 0, report time of all tests, if > 0,
115             report the time of the slowest `timer` tests. Default is -1.
116         tests : test or list of tests
117             Tests to be executed with pytest '--pyargs'
118 
119         Returns
120         -------
121         result : bool
122             Return True on success, false otherwise.
123 
124         Notes
125         -----
126         Each NumPy module exposes `test` in its namespace to run all tests for
127         it. For example, to run all tests for numpy.lib:
128 
129         >>> np.lib.test() #doctest: +SKIP
130 
131         Examples
132         --------
133         >>> result = np.lib.test() #doctest: +SKIP
134         ...
135         1023 passed, 2 skipped, 6 deselected, 1 xfailed in 10.39 seconds
136         >>> result
137         True
138 
139         """
140         import pytest
141         import warnings
142 
143         module = sys.modules[self.module_name]
144         module_path = os.path.abspath(module.__path__[0])
145 
146         # setup the pytest arguments
147         pytest_args = ["-l"]
148 
149         # offset verbosity. The "-q" cancels a "-v".
150         pytest_args += ["-q"]
151 
152         # Filter out distutils cpu warnings (could be localized to
153         # distutils tests). ASV has problems with top level import,
154         # so fetch module for suppression here.
155         with warnings.catch_warnings():
156             warnings.simplefilter("always")
157             from numpy.distutils import cpuinfo
158 
159         # Filter out annoying import messages. Want these in both develop and
160         # release mode.
161         pytest_args += [
162             "-W ignore:Not importing directory",
163             "-W ignore:numpy.dtype size changed",
164             "-W ignore:numpy.ufunc size changed",
165             "-W ignore::UserWarning:cpuinfo",
166             ]
167 
168         # When testing matrices, ignore their PendingDeprecationWarnings
169         pytest_args += [
170             "-W ignore:the matrix subclass is not",
171             "-W ignore:Importing from numpy.matlib is",
172             ]
173 
174         if doctests:
175             raise ValueError("Doctests not supported")
176 
177         if extra_argv:
178             pytest_args += list(extra_argv)
179 
180         if verbose > 1:
181             pytest_args += ["-" + "v"*(verbose - 1)]
182 
183         if coverage:
184             pytest_args += ["--cov=" + module_path]
185 
186         if label == "fast":
187             # not importing at the top level to avoid circular import of module
188             from numpy.testing import IS_PYPY
189             if IS_PYPY:
190                 pytest_args += ["-m", "not slow and not slow_pypy"]
191             else:
192                 pytest_args += ["-m", "not slow"]
193 
194         elif label != "full":
195             pytest_args += ["-m", label]
196 
197         if durations >= 0:
198             pytest_args += ["--durations=%s" % durations]
199 
200         if tests is None:
201             tests = [self.module_name]
202 
203         pytest_args += ["--pyargs"] + list(tests)
204 
205 
206         # run tests.
207         _show_numpy_info()
208 
209         try:
210             code = pytest.main(pytest_args)
211         except SystemExit as exc:
212             code = exc.code
213 
214         return code == 0
215
```
--- 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/numpy/_pytesttester.py b/numpy/_pytesttester.py
--- a/numpy/_pytesttester.py
+++ b/numpy/_pytesttester.py
@@ -140,6 +140,9 @@
         import pytest
         import warnings
 
+        # Imported after pytest to enable assertion rewriting
+        import hypothesis
+
         module = sys.modules[self.module_name]
         module_path = os.path.abspath(module.__path__[0])
 
@@ -202,6 +205,14 @@
 
         pytest_args += ["--pyargs"] + list(tests)
 
+        # This configuration is picked up by numpy.conftest, and ensures that
+        # running `np.test()` is deterministic and does not write any files.
+        # See https://hypothesis.readthedocs.io/en/latest/settings.html
+        hypothesis.settings.register_profile(
+            name="np.test() profile",
+            deadline=None, print_blob=True, database=None, derandomize=True,
+            suppress_health_check=hypothesis.HealthCheck.all(),
+        )
 
         # run tests.
         _show_numpy_info()
diff --git a/numpy/conftest.py b/numpy/conftest.py
--- a/numpy/conftest.py
+++ b/numpy/conftest.py
@@ -2,6 +2,7 @@
 Pytest configuration and fixtures for the Numpy test suite.
 """
 import os
+import tempfile
 
 import hypothesis
 import pytest
@@ -13,11 +14,23 @@
 _old_fpu_mode = None
 _collect_results = {}
 
+# Use a known and persistent tmpdir for hypothesis' caches, which
+# can be automatically cleared by the OS or user.
+hypothesis.configuration.set_hypothesis_home_dir(
+    os.path.join(tempfile.gettempdir(), ".hypothesis")
+)
 # See https://hypothesis.readthedocs.io/en/latest/settings.html
 hypothesis.settings.register_profile(
     name="numpy-profile", deadline=None, print_blob=True,
 )
-hypothesis.settings.load_profile("numpy-profile")
+# We try loading the profile defined by np.test(), which disables the
+# database and forces determinism, and fall back to the profile defined
+# above if we're running pytest directly.  The odd dance is required
+# because np.test() executes this file *after* its own setup code.
+try:
+    hypothesis.settings.load_profile("np.test() profile")
+except hypothesis.errors.InvalidArgument:  # profile not found
+    hypothesis.settings.load_profile("numpy-profile")
 
 
 def pytest_configure(config):

{"golden_diff": "diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py\n--- a/numpy/_pytesttester.py\n+++ b/numpy/_pytesttester.py\n@@ -140,6 +140,9 @@\n         import pytest\n         import warnings\n \n+        # Imported after pytest to enable assertion rewriting\n+        import hypothesis\n+\n         module = sys.modules[self.module_name]\n         module_path = os.path.abspath(module.__path__[0])\n \n@@ -202,6 +205,14 @@\n \n         pytest_args += [\"--pyargs\"] + list(tests)\n \n+        # This configuration is picked up by numpy.conftest, and ensures that\n+        # running `np.test()` is deterministic and does not write any files.\n+        # See https://hypothesis.readthedocs.io/en/latest/settings.html\n+        hypothesis.settings.register_profile(\n+            name=\"np.test() profile\",\n+            deadline=None, print_blob=True, database=None, derandomize=True,\n+            suppress_health_check=hypothesis.HealthCheck.all(),\n+        )\n \n         # run tests.\n         _show_numpy_info()\ndiff --git a/numpy/conftest.py b/numpy/conftest.py\n--- a/numpy/conftest.py\n+++ b/numpy/conftest.py\n@@ -2,6 +2,7 @@\n Pytest configuration and fixtures for the Numpy test suite.\n \"\"\"\n import os\n+import tempfile\n \n import hypothesis\n import pytest\n@@ -13,11 +14,23 @@\n _old_fpu_mode = None\n _collect_results = {}\n \n+# Use a known and persistent tmpdir for hypothesis' caches, which\n+# can be automatically cleared by the OS or user.\n+hypothesis.configuration.set_hypothesis_home_dir(\n+    os.path.join(tempfile.gettempdir(), \".hypothesis\")\n+)\n # See https://hypothesis.readthedocs.io/en/latest/settings.html\n hypothesis.settings.register_profile(\n     name=\"numpy-profile\", deadline=None, print_blob=True,\n )\n-hypothesis.settings.load_profile(\"numpy-profile\")\n+# We try loading the profile defined by np.test(), which disables the\n+# database and forces determinism, and fall back to the profile defined\n+# above if we're running pytest directly.  The odd dance is required\n+# because np.test() executes this file *after* its own setup code.\n+try:\n+    hypothesis.settings.load_profile(\"np.test() profile\")\n+except hypothesis.errors.InvalidArgument:  # profile not found\n+    hypothesis.settings.load_profile(\"numpy-profile\")\n \n \n def pytest_configure(config):\n", "issue": "MAINT: ignore `.hypothesis/`\n<!-- Please be sure you are following the instructions in the dev guidelines\r\nhttp://www.numpy.org/devdocs/dev/development_workflow.html\r\n-->\r\n\r\n<!-- We'd appreciate it if your commit message is properly formatted\r\nhttp://www.numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message\r\n-->\r\n\r\nI ran the test using `np.test()`. Then the `.hypothesis` directory was created. This seems to a byproduct of the test.\n", "before_files": [{"content": "\"\"\"\nPytest configuration and fixtures for the Numpy test suite.\n\"\"\"\nimport os\n\nimport hypothesis\nimport pytest\nimport numpy\n\nfrom numpy.core._multiarray_tests import get_fpu_mode\n\n\n_old_fpu_mode = None\n_collect_results = {}\n\n# See https://hypothesis.readthedocs.io/en/latest/settings.html\nhypothesis.settings.register_profile(\n    name=\"numpy-profile\", deadline=None, print_blob=True,\n)\nhypothesis.settings.load_profile(\"numpy-profile\")\n\n\ndef pytest_configure(config):\n    config.addinivalue_line(\"markers\",\n        \"valgrind_error: Tests that are known to error under valgrind.\")\n    config.addinivalue_line(\"markers\",\n        \"leaks_references: Tests that are known to leak references.\")\n    config.addinivalue_line(\"markers\",\n        \"slow: Tests that are very slow.\")\n    config.addinivalue_line(\"markers\",\n        \"slow_pypy: Tests that are very slow on pypy.\")\n\n\ndef pytest_addoption(parser):\n    parser.addoption(\"--available-memory\", action=\"store\", default=None,\n                     help=(\"Set amount of memory available for running the \"\n                           \"test suite. This can result to tests requiring \"\n                           \"especially large amounts of memory to be skipped. \"\n                           \"Equivalent to setting environment variable \"\n                           \"NPY_AVAILABLE_MEM. Default: determined\"\n                           \"automatically.\"))\n\n\ndef pytest_sessionstart(session):\n    available_mem = session.config.getoption('available_memory')\n    if available_mem is not None:\n        os.environ['NPY_AVAILABLE_MEM'] = available_mem\n\n\n#FIXME when yield tests are gone.\n@pytest.hookimpl()\ndef pytest_itemcollected(item):\n    \"\"\"\n    Check FPU precision mode was not changed during test collection.\n\n    The clumsy way we do it here is mainly necessary because numpy\n    still uses yield tests, which can execute code at test collection\n    time.\n    \"\"\"\n    global _old_fpu_mode\n\n    mode = get_fpu_mode()\n\n    if _old_fpu_mode is None:\n        _old_fpu_mode = mode\n    elif mode != _old_fpu_mode:\n        _collect_results[item] = (_old_fpu_mode, mode)\n        _old_fpu_mode = mode\n\n\n@pytest.fixture(scope=\"function\", autouse=True)\ndef check_fpu_mode(request):\n    \"\"\"\n    Check FPU precision mode was not changed during the test.\n    \"\"\"\n    old_mode = get_fpu_mode()\n    yield\n    new_mode = get_fpu_mode()\n\n    if old_mode != new_mode:\n        raise AssertionError(\"FPU precision mode changed from {0:#x} to {1:#x}\"\n                             \" during the test\".format(old_mode, new_mode))\n\n    collect_result = _collect_results.get(request.node)\n    if collect_result is not None:\n        old_mode, new_mode = collect_result\n        raise AssertionError(\"FPU precision mode changed from {0:#x} to {1:#x}\"\n                             \" when collecting the test\".format(old_mode,\n                                                                new_mode))\n\n\n@pytest.fixture(autouse=True)\ndef add_np(doctest_namespace):\n    doctest_namespace['np'] = numpy\n", "path": "numpy/conftest.py"}, {"content": "\"\"\"\nPytest test running.\n\nThis module implements the ``test()`` function for NumPy modules. The usual\nboiler plate for doing that is to put the following in the module\n``__init__.py`` file::\n\n    from numpy._pytesttester import PytestTester\n    test = PytestTester(__name__).test\n    del PytestTester\n\n\nWarnings filtering and other runtime settings should be dealt with in the\n``pytest.ini`` file in the numpy repo root. The behavior of the test depends on\nwhether or not that file is found as follows:\n\n* ``pytest.ini`` is present (develop mode)\n    All warnings except those explicitly filtered out are raised as error.\n* ``pytest.ini`` is absent (release mode)\n    DeprecationWarnings and PendingDeprecationWarnings are ignored, other\n    warnings are passed through.\n\nIn practice, tests run from the numpy repo are run in develop mode. That\nincludes the standard ``python runtests.py`` invocation.\n\nThis module is imported by every numpy subpackage, so lies at the top level to\nsimplify circular import issues. For the same reason, it contains no numpy\nimports at module scope, instead importing numpy within function calls.\n\"\"\"\nimport sys\nimport os\n\n__all__ = ['PytestTester']\n\n\n\ndef _show_numpy_info():\n    from numpy.core._multiarray_umath import (\n        __cpu_features__, __cpu_baseline__, __cpu_dispatch__\n    )\n    import numpy as np\n\n    print(\"NumPy version %s\" % np.__version__)\n    relaxed_strides = np.ones((10, 1), order=\"C\").flags.f_contiguous\n    print(\"NumPy relaxed strides checking option:\", relaxed_strides)\n\n    if len(__cpu_baseline__) == 0 and len(__cpu_dispatch__) == 0:\n        enabled_features = \"nothing enabled\"\n    else:\n        enabled_features = ' '.join(__cpu_baseline__)\n        for feature in __cpu_dispatch__:\n            if __cpu_features__[feature]:\n                enabled_features += \" %s*\" % feature\n            else:\n                enabled_features += \" %s?\" % feature\n    print(\"NumPy CPU features:\", enabled_features)\n\n\n\nclass PytestTester:\n    \"\"\"\n    Pytest test runner.\n\n    A test function is typically added to a package's __init__.py like so::\n\n      from numpy._pytesttester import PytestTester\n      test = PytestTester(__name__).test\n      del PytestTester\n\n    Calling this test function finds and runs all tests associated with the\n    module and all its sub-modules.\n\n    Attributes\n    ----------\n    module_name : str\n        Full path to the package to test.\n\n    Parameters\n    ----------\n    module_name : module name\n        The name of the module to test.\n\n    Notes\n    -----\n    Unlike the previous ``nose``-based implementation, this class is not\n    publicly exposed as it performs some ``numpy``-specific warning\n    suppression.\n\n    \"\"\"\n    def __init__(self, module_name):\n        self.module_name = module_name\n\n    def __call__(self, label='fast', verbose=1, extra_argv=None,\n                 doctests=False, coverage=False, durations=-1, tests=None):\n        \"\"\"\n        Run tests for module using pytest.\n\n        Parameters\n        ----------\n        label : {'fast', 'full'}, optional\n            Identifies the tests to run. When set to 'fast', tests decorated\n            with `pytest.mark.slow` are skipped, when 'full', the slow marker\n            is ignored.\n        verbose : int, optional\n            Verbosity value for test outputs, in the range 1-3. Default is 1.\n        extra_argv : list, optional\n            List with any extra arguments to pass to pytests.\n        doctests : bool, optional\n            .. note:: Not supported\n        coverage : bool, optional\n            If True, report coverage of NumPy code. Default is False.\n            Requires installation of (pip) pytest-cov.\n        durations : int, optional\n            If < 0, do nothing, If 0, report time of all tests, if > 0,\n            report the time of the slowest `timer` tests. Default is -1.\n        tests : test or list of tests\n            Tests to be executed with pytest '--pyargs'\n\n        Returns\n        -------\n        result : bool\n            Return True on success, false otherwise.\n\n        Notes\n        -----\n        Each NumPy module exposes `test` in its namespace to run all tests for\n        it. For example, to run all tests for numpy.lib:\n\n        >>> np.lib.test() #doctest: +SKIP\n\n        Examples\n        --------\n        >>> result = np.lib.test() #doctest: +SKIP\n        ...\n        1023 passed, 2 skipped, 6 deselected, 1 xfailed in 10.39 seconds\n        >>> result\n        True\n\n        \"\"\"\n        import pytest\n        import warnings\n\n        module = sys.modules[self.module_name]\n        module_path = os.path.abspath(module.__path__[0])\n\n        # setup the pytest arguments\n        pytest_args = [\"-l\"]\n\n        # offset verbosity. The \"-q\" cancels a \"-v\".\n        pytest_args += [\"-q\"]\n\n        # Filter out distutils cpu warnings (could be localized to\n        # distutils tests). ASV has problems with top level import,\n        # so fetch module for suppression here.\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"always\")\n            from numpy.distutils import cpuinfo\n\n        # Filter out annoying import messages. Want these in both develop and\n        # release mode.\n        pytest_args += [\n            \"-W ignore:Not importing directory\",\n            \"-W ignore:numpy.dtype size changed\",\n            \"-W ignore:numpy.ufunc size changed\",\n            \"-W ignore::UserWarning:cpuinfo\",\n            ]\n\n        # When testing matrices, ignore their PendingDeprecationWarnings\n        pytest_args += [\n            \"-W ignore:the matrix subclass is not\",\n            \"-W ignore:Importing from numpy.matlib is\",\n            ]\n\n        if doctests:\n            raise ValueError(\"Doctests not supported\")\n\n        if extra_argv:\n            pytest_args += list(extra_argv)\n\n        if verbose > 1:\n            pytest_args += [\"-\" + \"v\"*(verbose - 1)]\n\n        if coverage:\n            pytest_args += [\"--cov=\" + module_path]\n\n        if label == \"fast\":\n            # not importing at the top level to avoid circular import of module\n            from numpy.testing import IS_PYPY\n            if IS_PYPY:\n                pytest_args += [\"-m\", \"not slow and not slow_pypy\"]\n            else:\n                pytest_args += [\"-m\", \"not slow\"]\n\n        elif label != \"full\":\n            pytest_args += [\"-m\", label]\n\n        if durations >= 0:\n            pytest_args += [\"--durations=%s\" % durations]\n\n        if tests is None:\n            tests = [self.module_name]\n\n        pytest_args += [\"--pyargs\"] + list(tests)\n\n\n        # run tests.\n        _show_numpy_info()\n\n        try:\n            code = pytest.main(pytest_args)\n        except SystemExit as exc:\n            code = exc.code\n\n        return code == 0\n", "path": "numpy/_pytesttester.py"}], "after_files": [{"content": "\"\"\"\nPytest configuration and fixtures for the Numpy test suite.\n\"\"\"\nimport os\nimport tempfile\n\nimport hypothesis\nimport pytest\nimport numpy\n\nfrom numpy.core._multiarray_tests import get_fpu_mode\n\n\n_old_fpu_mode = None\n_collect_results = {}\n\n# Use a known and persistent tmpdir for hypothesis' caches, which\n# can be automatically cleared by the OS or user.\nhypothesis.configuration.set_hypothesis_home_dir(\n    os.path.join(tempfile.gettempdir(), \".hypothesis\")\n)\n# See https://hypothesis.readthedocs.io/en/latest/settings.html\nhypothesis.settings.register_profile(\n    name=\"numpy-profile\", deadline=None, print_blob=True,\n)\n# We try loading the profile defined by np.test(), which disables the\n# database and forces determinism, and fall back to the profile defined\n# above if we're running pytest directly.  The odd dance is required\n# because np.test() executes this file *after* its own setup code.\ntry:\n    hypothesis.settings.load_profile(\"np.test() profile\")\nexcept hypothesis.errors.InvalidArgument:  # profile not found\n    hypothesis.settings.load_profile(\"numpy-profile\")\n\n\ndef pytest_configure(config):\n    config.addinivalue_line(\"markers\",\n        \"valgrind_error: Tests that are known to error under valgrind.\")\n    config.addinivalue_line(\"markers\",\n        \"leaks_references: Tests that are known to leak references.\")\n    config.addinivalue_line(\"markers\",\n        \"slow: Tests that are very slow.\")\n    config.addinivalue_line(\"markers\",\n        \"slow_pypy: Tests that are very slow on pypy.\")\n\n\ndef pytest_addoption(parser):\n    parser.addoption(\"--available-memory\", action=\"store\", default=None,\n                     help=(\"Set amount of memory available for running the \"\n                           \"test suite. This can result to tests requiring \"\n                           \"especially large amounts of memory to be skipped. \"\n                           \"Equivalent to setting environment variable \"\n                           \"NPY_AVAILABLE_MEM. Default: determined\"\n                           \"automatically.\"))\n\n\ndef pytest_sessionstart(session):\n    available_mem = session.config.getoption('available_memory')\n    if available_mem is not None:\n        os.environ['NPY_AVAILABLE_MEM'] = available_mem\n\n\n#FIXME when yield tests are gone.\n@pytest.hookimpl()\ndef pytest_itemcollected(item):\n    \"\"\"\n    Check FPU precision mode was not changed during test collection.\n\n    The clumsy way we do it here is mainly necessary because numpy\n    still uses yield tests, which can execute code at test collection\n    time.\n    \"\"\"\n    global _old_fpu_mode\n\n    mode = get_fpu_mode()\n\n    if _old_fpu_mode is None:\n        _old_fpu_mode = mode\n    elif mode != _old_fpu_mode:\n        _collect_results[item] = (_old_fpu_mode, mode)\n        _old_fpu_mode = mode\n\n\n@pytest.fixture(scope=\"function\", autouse=True)\ndef check_fpu_mode(request):\n    \"\"\"\n    Check FPU precision mode was not changed during the test.\n    \"\"\"\n    old_mode = get_fpu_mode()\n    yield\n    new_mode = get_fpu_mode()\n\n    if old_mode != new_mode:\n        raise AssertionError(\"FPU precision mode changed from {0:#x} to {1:#x}\"\n                             \" during the test\".format(old_mode, new_mode))\n\n    collect_result = _collect_results.get(request.node)\n    if collect_result is not None:\n        old_mode, new_mode = collect_result\n        raise AssertionError(\"FPU precision mode changed from {0:#x} to {1:#x}\"\n                             \" when collecting the test\".format(old_mode,\n                                                                new_mode))\n\n\n@pytest.fixture(autouse=True)\ndef add_np(doctest_namespace):\n    doctest_namespace['np'] = numpy\n", "path": "numpy/conftest.py"}, {"content": "\"\"\"\nPytest test running.\n\nThis module implements the ``test()`` function for NumPy modules. The usual\nboiler plate for doing that is to put the following in the module\n``__init__.py`` file::\n\n    from numpy._pytesttester import PytestTester\n    test = PytestTester(__name__).test\n    del PytestTester\n\n\nWarnings filtering and other runtime settings should be dealt with in the\n``pytest.ini`` file in the numpy repo root. The behavior of the test depends on\nwhether or not that file is found as follows:\n\n* ``pytest.ini`` is present (develop mode)\n    All warnings except those explicitly filtered out are raised as error.\n* ``pytest.ini`` is absent (release mode)\n    DeprecationWarnings and PendingDeprecationWarnings are ignored, other\n    warnings are passed through.\n\nIn practice, tests run from the numpy repo are run in develop mode. That\nincludes the standard ``python runtests.py`` invocation.\n\nThis module is imported by every numpy subpackage, so lies at the top level to\nsimplify circular import issues. For the same reason, it contains no numpy\nimports at module scope, instead importing numpy within function calls.\n\"\"\"\nimport sys\nimport os\n\n__all__ = ['PytestTester']\n\n\n\ndef _show_numpy_info():\n    from numpy.core._multiarray_umath import (\n        __cpu_features__, __cpu_baseline__, __cpu_dispatch__\n    )\n    import numpy as np\n\n    print(\"NumPy version %s\" % np.__version__)\n    relaxed_strides = np.ones((10, 1), order=\"C\").flags.f_contiguous\n    print(\"NumPy relaxed strides checking option:\", relaxed_strides)\n\n    if len(__cpu_baseline__) == 0 and len(__cpu_dispatch__) == 0:\n        enabled_features = \"nothing enabled\"\n    else:\n        enabled_features = ' '.join(__cpu_baseline__)\n        for feature in __cpu_dispatch__:\n            if __cpu_features__[feature]:\n                enabled_features += \" %s*\" % feature\n            else:\n                enabled_features += \" %s?\" % feature\n    print(\"NumPy CPU features:\", enabled_features)\n\n\n\nclass PytestTester:\n    \"\"\"\n    Pytest test runner.\n\n    A test function is typically added to a package's __init__.py like so::\n\n      from numpy._pytesttester import PytestTester\n      test = PytestTester(__name__).test\n      del PytestTester\n\n    Calling this test function finds and runs all tests associated with the\n    module and all its sub-modules.\n\n    Attributes\n    ----------\n    module_name : str\n        Full path to the package to test.\n\n    Parameters\n    ----------\n    module_name : module name\n        The name of the module to test.\n\n    Notes\n    -----\n    Unlike the previous ``nose``-based implementation, this class is not\n    publicly exposed as it performs some ``numpy``-specific warning\n    suppression.\n\n    \"\"\"\n    def __init__(self, module_name):\n        self.module_name = module_name\n\n    def __call__(self, label='fast', verbose=1, extra_argv=None,\n                 doctests=False, coverage=False, durations=-1, tests=None):\n        \"\"\"\n        Run tests for module using pytest.\n\n        Parameters\n        ----------\n        label : {'fast', 'full'}, optional\n            Identifies the tests to run. When set to 'fast', tests decorated\n            with `pytest.mark.slow` are skipped, when 'full', the slow marker\n            is ignored.\n        verbose : int, optional\n            Verbosity value for test outputs, in the range 1-3. Default is 1.\n        extra_argv : list, optional\n            List with any extra arguments to pass to pytests.\n        doctests : bool, optional\n            .. note:: Not supported\n        coverage : bool, optional\n            If True, report coverage of NumPy code. Default is False.\n            Requires installation of (pip) pytest-cov.\n        durations : int, optional\n            If < 0, do nothing, If 0, report time of all tests, if > 0,\n            report the time of the slowest `timer` tests. Default is -1.\n        tests : test or list of tests\n            Tests to be executed with pytest '--pyargs'\n\n        Returns\n        -------\n        result : bool\n            Return True on success, false otherwise.\n\n        Notes\n        -----\n        Each NumPy module exposes `test` in its namespace to run all tests for\n        it. For example, to run all tests for numpy.lib:\n\n        >>> np.lib.test() #doctest: +SKIP\n\n        Examples\n        --------\n        >>> result = np.lib.test() #doctest: +SKIP\n        ...\n        1023 passed, 2 skipped, 6 deselected, 1 xfailed in 10.39 seconds\n        >>> result\n        True\n\n        \"\"\"\n        import pytest\n        import warnings\n\n        # Imported after pytest to enable assertion rewriting\n        import hypothesis\n\n        module = sys.modules[self.module_name]\n        module_path = os.path.abspath(module.__path__[0])\n\n        # setup the pytest arguments\n        pytest_args = [\"-l\"]\n\n        # offset verbosity. The \"-q\" cancels a \"-v\".\n        pytest_args += [\"-q\"]\n\n        # Filter out distutils cpu warnings (could be localized to\n        # distutils tests). ASV has problems with top level import,\n        # so fetch module for suppression here.\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"always\")\n            from numpy.distutils import cpuinfo\n\n        # Filter out annoying import messages. Want these in both develop and\n        # release mode.\n        pytest_args += [\n            \"-W ignore:Not importing directory\",\n            \"-W ignore:numpy.dtype size changed\",\n            \"-W ignore:numpy.ufunc size changed\",\n            \"-W ignore::UserWarning:cpuinfo\",\n            ]\n\n        # When testing matrices, ignore their PendingDeprecationWarnings\n        pytest_args += [\n            \"-W ignore:the matrix subclass is not\",\n            \"-W ignore:Importing from numpy.matlib is\",\n            ]\n\n        if doctests:\n            raise ValueError(\"Doctests not supported\")\n\n        if extra_argv:\n            pytest_args += list(extra_argv)\n\n        if verbose > 1:\n            pytest_args += [\"-\" + \"v\"*(verbose - 1)]\n\n        if coverage:\n            pytest_args += [\"--cov=\" + module_path]\n\n        if label == \"fast\":\n            # not importing at the top level to avoid circular import of module\n            from numpy.testing import IS_PYPY\n            if IS_PYPY:\n                pytest_args += [\"-m\", \"not slow and not slow_pypy\"]\n            else:\n                pytest_args += [\"-m\", \"not slow\"]\n\n        elif label != \"full\":\n            pytest_args += [\"-m\", label]\n\n        if durations >= 0:\n            pytest_args += [\"--durations=%s\" % durations]\n\n        if tests is None:\n            tests = [self.module_name]\n\n        pytest_args += [\"--pyargs\"] + list(tests)\n\n        # This configuration is picked up by numpy.conftest, and ensures that\n        # running `np.test()` is deterministic and does not write any files.\n        # See https://hypothesis.readthedocs.io/en/latest/settings.html\n        hypothesis.settings.register_profile(\n            name=\"np.test() profile\",\n            deadline=None, print_blob=True, database=None, derandomize=True,\n            suppress_health_check=hypothesis.HealthCheck.all(),\n        )\n\n        # run tests.\n        _show_numpy_info()\n\n        try:\n            code = pytest.main(pytest_args)\n        except SystemExit as exc:\n            code = exc.code\n\n        return code == 0\n", "path": "numpy/_pytesttester.py"}]}