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

1import pytest 

2 

3import prisma 

4from prisma import Prisma, register, get_client 

5from prisma.testing import reset_client, unregister_client 

6 

7 

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) 

13 

14 # ensure the test is sound 

15 assert Prisma() != original 

16 

17 with pytest.raises(prisma.errors.ClientAlreadyRegisteredError): 

18 register(Prisma()) 

19 

20 with reset_client(): 

21 with pytest.raises(prisma.errors.ClientNotRegisteredError): 

22 get_client() 

23 

24 with pytest.raises(prisma.errors.ClientNotRegisteredError): 

25 with reset_client(): 

26 ... 

27 

28 client = Prisma() 

29 register(client) 

30 assert get_client() == client 

31 

32 assert get_client() == original 

33 

34 

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() 

41 

42 with pytest.raises(prisma.errors.ClientNotRegisteredError): 

43 get_client() 

44 

45 with pytest.raises(prisma.errors.ClientNotRegisteredError): 

46 unregister_client() 

47 

48 # test cleanup 

49 register(original)