Coverage for tests/test_depends_hashable.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1# This is more or less a workaround to make Depends and Security hashable 

2# as other tools that use them depend on that 

3# Ref: https://github.com/fastapi/fastapi/pull/14320 

4 

5from fastapi import Depends, Security 1hijklmn

6 

7 

8def dep(): 1hijklmn

9 pass 1abcdefg

10 

11 

12def test_depends_hashable(): 1hijklmn

13 dep() # just for coverage 1abcdefg

14 d1 = Depends(dep) 1abcdefg

15 d2 = Depends(dep) 1abcdefg

16 d3 = Depends(dep, scope="function") 1abcdefg

17 d4 = Depends(dep, scope="function") 1abcdefg

18 

19 s1 = Security(dep) 1abcdefg

20 s2 = Security(dep) 1abcdefg

21 

22 assert hash(d1) == hash(d2) 1abcdefg

23 assert hash(s1) == hash(s2) 1abcdefg

24 assert hash(d1) != hash(d3) 1abcdefg

25 assert hash(d3) == hash(d4) 1abcdefg