Coverage for src/prisma/testing.py: 100%
19 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from __future__ import annotations
3import contextlib
4from typing import Iterator
6from . import _registry
7from .errors import ClientNotRegisteredError
8from ._registry import RegisteredClient
11@contextlib.contextmanager
12def reset_client(
13 new_client: RegisteredClient | None = None,
14) -> Iterator[None]:
15 """Context manager to unregister the current client
17 Once the context manager exits, the registered client is set back to it's original state
18 """
19 client = _registry._registered_client
20 if client is None:
21 raise ClientNotRegisteredError()
23 try:
24 _registry._registered_client = new_client
25 yield
26 finally:
27 _registry._registered_client = client
30def unregister_client() -> None:
31 """Unregister the current client."""
32 if _registry._registered_client is None:
33 raise ClientNotRegisteredError()
35 _registry._registered_client = None