{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This context manager monkey-patches modules and as such is thread unsafe on Dask and JAX. If you run your test suite with "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "pytest-run-parallel"
                }
              ],
              "url": "https://github.com/Quansight-Labs/pytest-run-parallel/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", you should mark these backends with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "@pytest.mark.thread_unsafe"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", as shown in the example above."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Test lazy execution of functions tagged with "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lazy_xp_function",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy._lib.array_api_extra.testing:lazy_xp_function"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "request",
              "annotation": "pytest.FixtureRequest",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Pytest fixture, as acquired by the test itself or by one of its fixtures."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "monkeypatch",
              "annotation": "pytest.MonkeyPatch",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Deprecated"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "xp",
              "annotation": "array_namespace",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Array namespace to be tested."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xp==jax.numpy"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", search for all functions which have been tagged with "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lazy_xp_function",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy._lib.array_api_extra.testing:lazy_xp_function"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the globals of the module that defines the current test, as well as in the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "lazy_xp_modules"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " list in the globals of the same module, and wrap them with "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "jax.jit",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Unwrap them at the end of the test."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xp==dask.array"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", wrap the functions with a decorator that disables "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "compute()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "persist()"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and ensures that exceptions and warnings are raised eagerly."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This function should be typically called by your library's "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "xp"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " fixture that runs tests on multiple backends      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "@pytest.fixture(params=[\n    numpy,\n    array_api_strict,\n    pytest.param(jax.numpy, marks=pytest.mark.thread_unsafe),\n    pytest.param(dask.array, marks=pytest.mark.thread_unsafe),\n])\ndef xp(request):\n    with patch_lazy_xp_functions(request, xp=request.param):\n        yield request.param",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "but it can be otherwise be called by the test itself too."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/_lib/array_api_extra/testing.py",
  "item_line": 218,
  "item_type": "function",
  "aliases": [
    "scipy.differentiate.xpx.testing.patch_lazy_xp_functions"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "lazy_xp_function",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy._lib.array_api_extra.testing:lazy_xp_function"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Tag a function to be tested on lazy backends."
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "pytest.FixtureRequest",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "pytest.FixtureRequest"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "request",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " test function parameter."
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "request",
        "annotation": "pytest.FixtureRequest",
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "monkeypatch",
        "annotation": "pytest.MonkeyPatch | None",
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "xp",
        "annotation": "ModuleType",
        "kind": "KEYWORD_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      }
    ],
    "return_annotation": "contextlib.AbstractContextManager[None]",
    "target_name": "patch_lazy_xp_functions"
  },
  "references": null,
  "qa": "scipy._lib.array_api_extra.testing:patch_lazy_xp_functions",
  "arbitrary": [],
  "local_refs": [
    "monkeypatch",
    "request",
    "xp"
  ]
}