Coverage for tests/test_testing.py: 100%
30 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
1import pytest
3import prisma
4from prisma import Prisma, register, get_client
5from prisma.testing import reset_client, unregister_client
8@pytest.mark.prisma
9def test_reset_client() -> None:
10 """Resetting and re-registering the registered client works as expected"""
11 original = get_client()
12 assert isinstance(original, Prisma)
14 # ensure the test is sound
15 assert Prisma() != original
17 with pytest.raises(prisma.errors.ClientAlreadyRegisteredError):
18 register(Prisma())
20 with reset_client():
21 with pytest.raises(prisma.errors.ClientNotRegisteredError):
22 get_client()
24 with pytest.raises(prisma.errors.ClientNotRegisteredError):
25 with reset_client():
26 ...
28 client = Prisma()
29 register(client)
30 assert get_client() == client
32 assert get_client() == original
35@pytest.mark.prisma
36def test_unregister_client() -> None:
37 """Unregistering the client works as expected"""
38 original = get_client()
39 assert isinstance(original, Prisma)
40 unregister_client()
42 with pytest.raises(prisma.errors.ClientNotRegisteredError):
43 get_client()
45 with pytest.raises(prisma.errors.ClientNotRegisteredError):
46 unregister_client()
48 # test cleanup
49 register(original)