|
5 | 5 | if sys.version_info < (3, 10): |
6 | 6 | pytest.skip("Annotated is available only for python 3.10+", allow_module_level=True) |
7 | 7 |
|
8 | | -from typing import Annotated, AsyncGenerator, Generic, TypeVar |
| 8 | +from typing import Annotated, AsyncGenerator, Generic, Tuple, TypeVar |
9 | 9 |
|
10 | 10 | from taskiq_dependencies import DependencyGraph, Depends |
11 | 11 |
|
@@ -74,3 +74,34 @@ def test_func(dep: Annotated[int, Depends(my_gen)]) -> int: |
74 | 74 | assert value == 1 |
75 | 75 |
|
76 | 76 | assert opened and closed |
| 77 | + |
| 78 | + |
| 79 | +def test_multiple() -> None: |
| 80 | + class TestClass: |
| 81 | + pass |
| 82 | + |
| 83 | + MyType = Annotated[TestClass, Depends(use_cache=False)] |
| 84 | + |
| 85 | + def test_func(dep: MyType, dep2: MyType) -> Tuple[MyType, MyType]: |
| 86 | + return dep, dep2 |
| 87 | + |
| 88 | + with DependencyGraph(target=test_func).sync_ctx(exception_propagation=False) as g: |
| 89 | + value = test_func(**(g.resolve_kwargs())) |
| 90 | + assert value[0] != value[1] |
| 91 | + assert isinstance(value[0], TestClass) |
| 92 | + assert isinstance(value[1], TestClass) |
| 93 | + |
| 94 | + |
| 95 | +def test_multiple_with_cache() -> None: |
| 96 | + class TestClass: |
| 97 | + pass |
| 98 | + |
| 99 | + MyType = Annotated[TestClass, Depends()] |
| 100 | + |
| 101 | + def test_func(dep: MyType, dep2: MyType) -> Tuple[MyType, MyType]: |
| 102 | + return dep, dep2 |
| 103 | + |
| 104 | + with DependencyGraph(target=test_func).sync_ctx(exception_propagation=False) as g: |
| 105 | + value = test_func(**(g.resolve_kwargs())) |
| 106 | + assert id(value[0]) == id(value[1]) |
| 107 | + assert isinstance(value[0], TestClass) |
0 commit comments