Repository: reagento/dishka
Pull request #391 (2025-03-12 17:56:05)

fix substituting kwargs with some names


Patch:
diff --git a/docs/contributing.rst b/docs/contributing.rst
index ad4a670..6b161e5 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -25,7 +25,7 @@ Getting started
 .. code-block::
 
     pip install -r requirements_dev.txt
-    uv pip install -e .
+    pip install -e .
 
 Running linters
 =====================
@@ -45,24 +45,16 @@ Running tests
 ========================
 
 Project contains several types of tests:
-
 * unit tests of library itself
 * integration with other libraries
 * tests of example app
 
-All of them can be run using nox:
+All of them can be run using tox:
 
 .. code-block::
 
     nox
 
-You can run integration tests for all specified versions of library:
-
-.. code-block::
-
-    nox -t aiohttp
-
-
 All integration tests are using specific versions of libraries by default. You can run them with latest version specifying it explicitly. E.g.:
 
 .. code-block::
diff --git a/noxfile.py b/noxfile.py
index 3377219..1d08f04 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -11,17 +11,11 @@ CMD = ("pytest", "--cov=dishka", "--cov-append", "--cov-report=term-missing", "-
 INSTALL_CMD = ("pytest", "pytest-cov", "-e", ".")
 
 
-@dataclass(frozen=True, slots=True)
-class Constraint:
-    reason: str = ""
-    condition: Callable[[], bool] = lambda: True
-
-
 @dataclass(frozen=True, slots=True)
 class IntegrationEnv:
     library: str
     version: str
-    constraint: Constraint | None = None
+    constraint: Callable[[], bool] = lambda: True
 
     def get_req(self) -> str:
         return f"requirements/{self.library.replace('_', '-')}-{self.version}.txt"
@@ -30,13 +24,8 @@ class IntegrationEnv:
         return f"tests/integrations/{self.library}"
 
 
-constraint_3_13 = Constraint(
-    "Skip tests on python 3.13 due to compatibility issues",
-    lambda: sys.version_info < (3, 13),
-)
-
 INTEGRATIONS = [
-    IntegrationEnv("aiogram", "330", constraint_3_13),
+    IntegrationEnv("aiogram", "330", lambda: sys.version_info < (3, 13)),
     IntegrationEnv("aiogram", "3140"),
     IntegrationEnv("aiogram", "latest"),
     IntegrationEnv("aiogram_dialog", "210"),
@@ -50,13 +39,13 @@ INTEGRATIONS = [
     IntegrationEnv("fastapi", "0096"),
     IntegrationEnv("fastapi", "0109"),
     IntegrationEnv("fastapi", "latest"),
-    IntegrationEnv("faststream", "047", constraint_3_13),
-    IntegrationEnv("faststream", "050", constraint_3_13),
+    IntegrationEnv("faststream", "047", lambda: sys.version_info < (3, 13)),
+    IntegrationEnv("faststream", "050", lambda: sys.version_info < (3, 13)),
     IntegrationEnv("faststream", "0529"),
     IntegrationEnv("faststream", "latest"),
     IntegrationEnv("flask", "302"),
     IntegrationEnv("flask", "latest"),
-    IntegrationEnv("grpcio", "1641", constraint_3_13),
+    IntegrationEnv("grpcio", "1641", lambda: sys.version_info < (3, 13)),
     IntegrationEnv("grpcio", "1680"),
     IntegrationEnv("grpcio", "latest"),
     IntegrationEnv("litestar", "230"),
@@ -79,7 +68,6 @@ def integrations_base(session: nox.Session) -> None:
     session.install(
         *INSTALL_CMD,
         "-r", "requirements/test.txt",
-        silent=False,
     )
     session.run(*CMD, "tests/integrations/base")
 
@@ -90,10 +78,9 @@ for env in INTEGRATIONS:
         tags=[env.library, "latest" if env.version == "latest" else "ci"],
     )
     def session(session: nox.Session, env=env) -> None:
-        if env.constraint and not env.constraint.condition():
-            session.skip(env.constraint.reason)
-
-        session.install(*INSTALL_CMD, "-r", env.get_req(), silent=False)
+        if not env.constraint():
+            session.skip("Skip tests on python 3.13 due to compatibility issues")
+        session.install(*INSTALL_CMD, "-r", env.get_req())
         session.run(*CMD, env.get_tests())
 
 
@@ -102,7 +89,6 @@ def unit(session: nox.Session) -> None:
     session.install(
         *INSTALL_CMD,
         "-r", "requirements/test.txt",
-        silent=False,
     )
     session.run(*CMD, "tests/unit")
 
@@ -112,6 +98,5 @@ def real_world(session: nox.Session) -> None:
     session.install(
         *INSTALL_CMD,
         "-r", "examples/real_world/requirements_test.txt",
-        silent=False,
     )
     session.run(*CMD, "examples/real_world/tests/")
diff --git a/src/dishka/factory_compiler.py b/src/dishka/factory_compiler.py
index da0b627..4c086f6 100644
--- a/src/dishka/factory_compiler.py
+++ b/src/dishka/factory_compiler.py
@@ -25,21 +25,12 @@ from .dependency_source import Factory
 from .exceptions import NoContextValueError, UnsupportedFactoryError
 
 
-def make_args(args: list[str], kwargs: list[str]) -> str:
-    res = ", ".join(
-        f"{{await}}getter({arg})"
-        for arg in args
+def make_args(args: list[str], kwargs: dict[str, str]) -> str:
+    """Format arguments for the factory function."""
+    return ", ".join(
+        [f"{{await}}getter({arg})" for arg in args] +
+        [f"{arg}={{await}}getter({var})" for arg, var in kwargs.items()],
     )
-    if not kwargs:
-        return res
-    if res:
-        res += ", "
-    res += ", ".join(
-        f"{arg}={{await}}getter({arg})"
-        for arg in kwargs
-    )
-    return res
-
 
 GENERATOR = """
 {async}def get(getter, exits, context):
@@ -115,7 +106,14 @@ def compile_factory(*, factory: Factory, is_async: bool) -> CompiledFactory:
         f"_dishka_arg{i}": dep
         for i, dep in enumerate(factory.dependencies)
     }
-    kwargs = factory.kw_dependencies
+    kwargs_to_globals = {
+        name: f"_dishka_kwarg_{name}"
+        for name in factory.kw_dependencies
+    }
+    kwargs = {
+        kwargs_to_globals[name]: dep
+        for name, dep in factory.kw_dependencies.items()
+    }
 
     if is_async:
         async_ = "async "
@@ -125,19 +123,15 @@ def compile_factory(*, factory: Factory, is_async: bool) -> CompiledFactory:
         async_ = ""
         await_ = ""
         body_template = SYNC_BODIES.get(factory.type, INVALID)
-    if factory.cache:
-        cache = CACHE
-    else:
-        cache = ""
 
-    args_str = make_args(list(args), list(kwargs)).format_map({
+    args_str = make_args(list(args), kwargs_to_globals).format_map({
         "await": await_,
     })
     body = body_template.format_map({
         "async": async_,
         "await": await_,
         "args": args_str,
-        "cache": cache,
+        "cache": CACHE if factory.cache else "",
     })
     func_globals = {
         "source": factory.source,
diff --git a/src/dishka/integrations/base.py b/src/dishka/integrations/base.py
index 94456e0..24424b4 100644
--- a/src/dishka/integrations/base.py
+++ b/src/dishka/integrations/base.py
@@ -157,7 +157,6 @@ def wrap_injection(
             ),
         )
 
-    auto_injected_func.__dishka_orig_func__ = func
     auto_injected_func.__dishka_injected__ = True  # type: ignore[attr-defined]
     auto_injected_func.__name__ = func.__name__
     auto_injected_func.__qualname__ = func.__qualname__
diff --git a/src/dishka/integrations/faststream.py b/src/dishka/integrations/faststream.py
index 8900bb9..b1bbe43 100644
--- a/src/dishka/integrations/faststream.py
+++ b/src/dishka/integrations/faststream.py
@@ -8,19 +8,10 @@ __all__ = (
 import warnings
 from collections.abc import AsyncIterator, Awaitable, Callable
 from contextlib import asynccontextmanager
-from typing import (
-    Any,
-    ParamSpec,
-    Protocol,
-    TypeAlias,
-    TypeVar,
-    cast,
-)
+from typing import Any, ParamSpec, TypeVar, cast
 
 from faststream import BaseMiddleware, FastStream, context
-from faststream.__about__ import (
-    __version__ as FASTSTREAM_VERSION,  # noqa: N812
-)
+from faststream.__about__ import __version__
 from faststream.broker.message import StreamMessage
 from faststream.types import DecodedMessage
 from faststream.utils.context import ContextRepo
@@ -28,128 +19,82 @@ from faststream.utils.context import ContextRepo
 from dishka import AsyncContainer, FromDishka, Provider, Scope, from_context
 from dishka.integrations.base import wrap_injection
 
+T = TypeVar("T")
+P = ParamSpec("P")
+
 
 class FastStreamProvider(Provider):
     context = from_context(ContextRepo, scope=Scope.REQUEST)
     message = from_context(StreamMessage, scope=Scope.REQUEST)
 
 
-FASTSTREAM_04 = FASTSTREAM_VERSION.startswith("0.4")
-FASTSTREAM_05 = FASTSTREAM_VERSION.startswith("0.5")
-FASTSTREAM_LATES = not FASTSTREAM_04 and not FASTSTREAM_05
-
-if FASTSTREAM_04:
-    warnings.warn(
-        "FastStream 0.4 is deprecated and integration will be removed"
-        " in the 1.6.0 dishka release.",
-        category=DeprecationWarning,
-        stacklevel=1,
-    )
-
-    from faststream.broker.core.abc import (  # type: ignore[attr-defined]
-        BrokerUsecase as BrokerType,
-    )
-
-    Application: TypeAlias = FastStream
+FASTSTREAM_OLD_MIDDLEWARES = __version__ < "0.5"
 
-    try:
-        from faststream.broker.fastapi import StreamRouter
-    except ImportError:
-        pass
-    else:
-        Application |= StreamRouter  # type: ignore[assignment]
 
-elif FASTSTREAM_05:
-    from faststream.broker.core.usecase import BrokerUsecase as BrokerType
-
-    if FASTSTREAM_VERSION < "0.5.16":
-        warnings.warn(
-            "FastStream < 0.5.16 is deprecated and integration will be removed"
-            " in the 1.7.0 dishka release.",
-            category=DeprecationWarning,
-            stacklevel=1,
-        )
+class _DishkaBaseMiddleware(BaseMiddleware):
+    def __init__(self, container: AsyncContainer) -> None:
+        self.container = container
 
-        Application: TypeAlias = FastStream  # type: ignore[no-redef,misc]
+    def __call__(self, msg: Any | None = None) -> "_DishkaBaseMiddleware":
+        self.msg = msg
+        return self
 
-    else:
-        from faststream.asgi import AsgiFastStream
 
-        Application: TypeAlias = FastStream | AsgiFastStream  # type: ignore[no-redef,misc]
+if FASTSTREAM_OLD_MIDDLEWARES:
 
-    try:
-        from faststream.broker.fastapi import StreamRouter
-    except ImportError:
-        pass
-    else:
-        Application |= StreamRouter  # type: ignore[assignment]
+    class DishkaMiddleware(_DishkaBaseMiddleware):
+        @asynccontextmanager
+        async def consume_scope(  # type: ignore[override]
+                self,
+                *args: Any,
+                **kwargs: Any,
+        ) -> AsyncIterator[DecodedMessage]:
+            async with self.container() as request_container:
+                with context.scope("dishka", request_container):
+                    async with super().consume_scope(  # type: ignore[attr-defined]
+                        *args,
+                        **kwargs,
+                    ) as result:
+                        yield result
 
 else:
-    from faststream._internal.broker.broker import BrokerUsecase as BrokerType
-    from faststream.asgi import AsgiFastStream
-
-    Application: TypeAlias = FastStream | AsgiFastStream  # type: ignore[no-redef,misc]
-
-    try:
-        from faststream._internal.fastapi import (  # type: ignore[no-redef]
-            StreamRouter,
-        )
-    except ImportError:
-        pass
-    else:
-        Application |= StreamRouter  # type: ignore[assignment]
 
-
-class ApplicationLike(Protocol):
-    broker: BrokerType[Any, Any]
+    class DishkaMiddleware(_DishkaBaseMiddleware):  # type: ignore[no-redef]
+        async def consume_scope(
+                self,
+                call_next: Callable[[Any], Awaitable[Any]],
+                msg: StreamMessage[Any],
+        ) -> AsyncIterator[DecodedMessage]:
+            async with self.container(
+                {
+                    StreamMessage: msg,
+                    ContextRepo: context,
+                    type(msg): msg,
+                },
+            ) as request_container:
+                with context.scope("dishka", request_container):
+                    return cast(
+                        AsyncIterator[DecodedMessage],
+                        await call_next(msg),
+                    )
 
 
 def setup_dishka(
-    container: AsyncContainer,
-    app: "Application | ApplicationLike | None" = None,
-    broker: "BrokerType[Any, Any] | None" = None,
-    *,
-    finalize_container: bool = True,
-    auto_inject: bool = False,
+        container: AsyncContainer,
+        app: FastStream,
+        *,
+        finalize_container: bool = True,
+        auto_inject: bool = False,
 ) -> None:
-    """
-    Setup dishka integration with FastStream.
-    You must provide either app or broker.
-
-    Args:
-        container: AsyncContainer instance.
-        app: FastStream Application or StreamRouter instance.
-        broker: FastStream broker instance.
-        finalize_container: bool. Can be used only with app.
-        auto_inject: bool.
-    """
-    if (app and broker) or (not app and not broker):
-        raise ValueError(  # noqa: TRY003
-            "You must provide either app or broker "
-            "to setup dishka integration.",
-        )
+    assert app.broker, "You can't patch FastStream application without broker"  # noqa: S101
 
     if finalize_container:
-        if getattr(app, "after_shutdown", None):
-            app.after_shutdown(container.close)  # type: ignore[union-attr]
-
-        else:
-            warnings.warn(
-                "For use `finalize_container=True` "
-                "you must provide `app: FastStream | AsgiFastStream` "
-                "argument.",
-                category=RuntimeWarning,
-                stacklevel=2,
-            )
+        app.after_shutdown(container.close)
 
-    broker = broker or getattr(app, "broker", None)
-    assert broker  # noqa: S101
-
-    if FASTSTREAM_04:
-        # FastStream 0.4 - 0.5
-        broker.middlewares = (
+    if FASTSTREAM_OLD_MIDDLEWARES:
+        app.broker.middlewares = (  # type: ignore[attr-defined]
             DishkaMiddleware(container),
-            *broker.middlewares,
+            *app.broker.middlewares,  # type: ignore[attr-defined]
         )
 
         if auto_inject:
@@ -160,50 +105,32 @@ Please, update your FastStream installation
 or use @inject at each subscriber manually.
             """,
                 category=RuntimeWarning,
-                stacklevel=2,
+                stacklevel=1,
             )
 
-        return
-
-    elif getattr(broker, "add_middleware", None):
-        # FastStream 0.5.6 and higher
-        broker.add_middleware(DishkaMiddleware(container))
-
     else:
-        # FastStream 0.5 - 0.5.6
-        warnings.warn(
-            "FastStream < 0.5.6 is deprecated and integration will be removed"
-            " in the 1.7.0 dishka release.",
-            category=DeprecationWarning,
-            stacklevel=2,
-        )
-
-        broker._middlewares = (  # noqa: SLF001
+        app.broker._middlewares = (  # noqa: SLF001
             DishkaMiddleware(container),
-            *broker._middlewares,  # noqa: SLF001
+            *app.broker._middlewares,  # noqa: SLF001
         )
 
-        for subscriber in broker._subscribers.values():  # noqa: SLF001
+        for subscriber in app.broker._subscribers.values():  # noqa: SLF001
             subscriber._broker_middlewares = (  # noqa: SLF001
                 DishkaMiddleware(container),
                 *subscriber._broker_middlewares,  # noqa: SLF001
             )
 
-        for publisher in broker._publishers.values():  # noqa: SLF001
+        for publisher in app.broker._publishers.values():  # noqa: SLF001
             publisher._broker_middlewares = (  # noqa: SLF001
                 DishkaMiddleware(container),
                 *publisher._broker_middlewares,  # noqa: SLF001
             )
 
-    if auto_inject:
-        broker._call_decorators = (  # noqa: SLF001
-            inject,
-            *broker._call_decorators,  # noqa: SLF001
-        )
-
-
-T = TypeVar("T")
-P = ParamSpec("P")
+        if auto_inject:
+            app.broker._call_decorators = (  # noqa: SLF001
+                inject,
+                *app.broker._call_decorators,  # noqa: SLF001
+            )
 
 
 def inject(func: Callable[P, T]) -> Callable[P, T]:
@@ -212,79 +139,3 @@ def inject(func: Callable[P, T]) -> Callable[P, T]:
         is_async=True,
         container_getter=lambda *_: context.get_local("dishka"),
     )
-
-
-class _DishkaMiddleware(BaseMiddleware):
-    def __init__(
-        self,
-        container: AsyncContainer,
-        *args: Any,
-        **kwargs: Any,
-    ) -> None:
-        self.container = container
-        super().__init__(*args, **kwargs)
-
-    if FASTSTREAM_04:
-
-        @asynccontextmanager
-        async def consume_scope(  # type: ignore[override]
-            self,
-            *args: Any,
-            **kwargs: Any,
-        ) -> AsyncIterator[DecodedMessage]:
-            async with self.container({
-                ContextRepo: context,
-            }) as request_container:
-                with context.scope("dishka", request_container):
-                    async with super().consume_scope(  # type: ignore[attr-defined]
-                        *args,
-                        **kwargs,
-                    ) as result:
-                        yield result
-
-    elif FASTSTREAM_05:
-
-        async def consume_scope(  # type: ignore[misc]
-            self,
-            call_next: Callable[[Any], Awaitable[Any]],
-            msg: StreamMessage[Any],
-        ) -> AsyncIterator[DecodedMessage]:
-            async with self.container(
-                {
-                    StreamMessage: msg,
-                    ContextRepo: context,
-                    type(msg): msg,
-                },
-            ) as request_container:
-                with context.scope("dishka", request_container):
-                    return cast(
-                        AsyncIterator[DecodedMessage],
-                        await call_next(msg),
-                    )
-
-    else:
-        async def consume_scope(  # type: ignore[misc]
-            self,
-            call_next: Callable[[Any], Awaitable[Any]],
-            msg: StreamMessage[Any],
-        ) -> AsyncIterator[DecodedMessage]:
-            async with self.container(
-                {
-                    StreamMessage: msg,
-                    ContextRepo: context,
-                    type(msg): msg,
-                },
-            ) as request_container:
-                with self.context.scope("dishka", request_container):  # type: ignore[attr-defined]
-                    return cast(
-                        AsyncIterator[DecodedMessage],
-                        await call_next(msg),
-                    )
-
-
-class DishkaMiddleware:
-    def __init__(self, container: AsyncContainer) -> None:
-        self.container = container
-
-    def __call__(self, *args: Any, **kwargs: Any) -> "_DishkaMiddleware":
-        return _DishkaMiddleware(self.container, *args, **kwargs)


Test patch:
diff --git a/tests/integrations/common.py b/tests/integrations/common.py
index ee6b5fc..ed57405 100644
--- a/tests/integrations/common.py
+++ b/tests/integrations/common.py
@@ -17,7 +17,7 @@ AppMock = NewType("AppMock", Mock)
 
 
 class AppProvider(Provider):
-    def __init__(self) -> None:
+    def __init__(self):
         super().__init__()
         self.app_released = Mock()
         self.request_released = Mock()
@@ -41,7 +41,7 @@ class AppProvider(Provider):
         self.websocket_released()
 
     @provide(scope=Scope.REQUEST)
-    def get_mock(self) -> Mock:
+    def mock(self) -> Mock:
         return self.mock
 
     @provide(scope=Scope.APP)
@@ -50,7 +50,7 @@ class AppProvider(Provider):
 
 
 class WebSocketAppProvider(Provider):
-    def __init__(self) -> None:
+    def __init__(self):
         super().__init__()
         self.app_released = Mock()
         self.request_released = Mock()
@@ -73,5 +73,5 @@ class WebSocketAppProvider(Provider):
         self.websocket_released()
 
     @provide(scope=Scope.SESSION)
-    def get_mock(self) -> Mock:
+    def mock(self) -> Mock:
         return self.mock
diff --git a/tests/integrations/conftest.py b/tests/integrations/conftest.py
index 642aa93..bb53324 100644
--- a/tests/integrations/conftest.py
+++ b/tests/integrations/conftest.py
@@ -5,19 +5,19 @@ from .common import AppProvider, WebSocketAppProvider
 
 
 @pytest.fixture
-def app_provider() -> AppProvider:
+def app_provider():
     return AppProvider()
 
 
 @pytest.fixture
-def ws_app_provider() -> WebSocketAppProvider:
+def ws_app_provider():
     return WebSocketAppProvider()
 
 @pytest.fixture
-def async_container(app_provider: AppProvider) -> AppProvider:
+def async_container(app_provider):
     return make_async_container(app_provider)
 
 
 @pytest.fixture
-def container(app_provider: AppProvider) -> AppProvider:
+def container(app_provider):
     return make_container(app_provider)
diff --git a/tests/integrations/faststream/test_faststream.py b/tests/integrations/faststream/test_faststream.py
index a0f6b20..b8cb739 100644
--- a/tests/integrations/faststream/test_faststream.py
+++ b/tests/integrations/faststream/test_faststream.py
@@ -1,6 +1,5 @@
-from collections.abc import AsyncIterator, Callable
+from collections.abc import AsyncIterator
 from contextlib import asynccontextmanager
-from typing import Any
 from unittest.mock import Mock
 
 import pytest
@@ -9,7 +8,7 @@ from faststream.nats import NatsBroker, TestNatsBroker
 
 from dishka import make_async_container
 from dishka.integrations.faststream import (
-    FASTSTREAM_04,
+    FASTSTREAM_OLD_MIDDLEWARES,
     FromDishka,
     inject,
     setup_dishka,
@@ -24,10 +23,7 @@ from ..common import (
 
 
 @asynccontextmanager
-async def dishka_app(
-    view: Callable[..., Any],
-    provider: AppProvider,
-) -> AsyncIterator[NatsBroker]:
+async def dishka_app(view, provider) -> AsyncIterator[NatsBroker]:
     broker = NatsBroker()
     broker.subscriber("test")(inject(view))
 
@@ -51,7 +47,7 @@ async def get_with_app(
 
 
 @pytest.mark.asyncio
-async def test_app_dependency(app_provider: AppProvider) -> None:
+async def test_app_dependency(app_provider: AppProvider):
     async with dishka_app(get_with_app, app_provider) as client:
         assert await client.publish("", "test", rpc=True) == "passed"
 
@@ -69,7 +65,7 @@ async def get_with_request(
 
 
 @pytest.mark.asyncio
-async def test_request_dependency(app_provider: AppProvider) -> None:
+async def test_request_dependency(app_provider: AppProvider):
     async with dishka_app(get_with_request, app_provider) as client:
         assert await client.publish("", "test", rpc=True) == "passed"
 
@@ -79,10 +75,10 @@ async def test_request_dependency(app_provider: AppProvider) -> None:
 
 @pytest.mark.asyncio
 @pytest.mark.skipif(
-    FASTSTREAM_04,
+    FASTSTREAM_OLD_MIDDLEWARES,
     reason="Requires FastStream 0.5.0+",
 )
-async def test_autoinject_before_subscriber(app_provider: AppProvider) -> None:
+async def test_autoinject_before_subscriber(app_provider: AppProvider):
     broker = NatsBroker()
     app = FastStream(broker)
 
@@ -102,10 +98,10 @@ async def test_autoinject_before_subscriber(app_provider: AppProvider) -> None:
 
 @pytest.mark.asyncio
 @pytest.mark.skipif(
-    FASTSTREAM_04,
+    FASTSTREAM_OLD_MIDDLEWARES,
     reason="Requires FastStream 0.5.0+",
 )
-async def test_autoinject_after_subscriber(app_provider: AppProvider) -> None:
+async def test_autoinject_after_subscriber(app_provider: AppProvider):
     broker = NatsBroker()
     app = FastStream(broker)
 
@@ -121,23 +117,3 @@ async def test_autoinject_after_subscriber(app_provider: AppProvider) -> None:
         app_provider.request_released.assert_called_once()
 
     await container.close()
-
-
-@pytest.mark.asyncio
-@pytest.mark.skipif(
-    FASTSTREAM_04,
-    reason="Requires FastStream 0.5.0+",
-)
-async def test_faststream_with_broker(app_provider: AppProvider) -> None:
-    broker = NatsBroker()
-    broker.subscriber("test")(get_with_request)
-    container = make_async_container(app_provider)
-    setup_dishka(container, broker=broker, auto_inject=True)
-
-    async with TestNatsBroker(broker) as br:
-        assert await br.publish("", "test", rpc=True) == "passed"
-
-        app_provider.mock.assert_called_with(REQUEST_DEP_VALUE)
-        app_provider.request_released.assert_called_once()
-
-    await container.close()
diff --git a/tests/unit/container/test_decorator.py b/tests/unit/container/test_decorator.py
index 153f43e..24a8d5f 100644
--- a/tests/unit/container/test_decorator.py
+++ b/tests/unit/container/test_decorator.py
@@ -77,8 +77,8 @@ def test_decorator():
     assert isinstance(a.a, A)
 
 
-def kwarg_decorator(x: int, *, a: A) -> A:
-    return ADecorator(a)
+def kwarg_decorator(x: int, *, source: A) -> A:
+    return ADecorator(source)
 
 
 def test_kwargs():
diff --git a/tests/unit/container/test_generic.py b/tests/unit/container/test_generic.py
index 4ef81cf..63799f1 100644
--- a/tests/unit/container/test_generic.py
+++ b/tests/unit/container/test_generic.py
@@ -249,6 +249,7 @@ def test_provide_partial_generic():
     provider.provide(func_with_at2)
     container = make_container(provider)
     assert container.get(Multi[int, A[bool]]) is bool
+    provider = Provider(scope=Scope.APP)
 
     provider = Provider(scope=Scope.APP)
     provider.provide(func_with_t2t)
diff --git a/tests/unit/plotter/test_wrappers.py b/tests/unit/plotter/test_wrappers.py
index 70ab7bb..76272ae 100644
--- a/tests/unit/plotter/test_wrappers.py
+++ b/tests/unit/plotter/test_wrappers.py
@@ -1,12 +1,9 @@
-from typing import Protocol
-
 import pytest
 
 from dishka import (
     Provider,
     Scope,
     alias,
-    decorate,
     make_async_container,
     make_container,
     provide,
@@ -14,24 +11,12 @@ from dishka import (
 from dishka.plotter import render_d2, render_mermaid
 
 
-class P(Protocol):
-    pass
-
-
 class MyProvider(Provider):
     component = "XXX"
     @provide(scope=Scope.APP)
     def foo(self) -> int:
         return 1
 
-    @provide(scope=Scope.REQUEST)
-    def bar(self, i: int) -> P:
-        ...
-
-    @decorate
-    def foobar(self, i: int) -> int:
-        return i
-
     float_alias = alias(source=int, provides=float)
 
 
diff --git a/tests/unit/test_provider.py b/tests/unit/test_provider.py
index 5a65be3..6cc04e3 100644
--- a/tests/unit/test_provider.py
+++ b/tests/unit/test_provider.py
@@ -1,15 +1,5 @@
-from collections.abc import (
-    AsyncGenerator,
-    AsyncIterable,
-    AsyncIterator,
-    Generator,
-    Iterable,
-    Iterator,
-)
-from functools import partial
 from random import random
-from types import NoneType
-from typing import Annotated, Any, Protocol
+from typing import Any, Protocol
 
 import pytest
 
@@ -19,14 +9,6 @@ from dishka.entities.key import (
     hint_to_dependency_key,
     hints_to_dependency_keys,
 )
-from dishka.provider.exceptions import (
-    MissingHintsError,
-    MissingReturnHintError,
-    NoScopeSetInContextError,
-    NoScopeSetInProvideError,
-    NotAFactoryError,
-    UndefinedTypeAnalysisError,
-)
 from dishka.provider.make_factory import make_factory, provide_all
 from .sample_providers import (
     ClassA,
@@ -80,24 +62,6 @@ def test_parse_factory(source, provider_type, is_to_bound):
     assert factory.type == provider_type
 
 
-def test_provide_no_scope():
-    provider = Provider()
-    with pytest.raises(NoScopeSetInProvideError):
-        provider.provide(source=int)
-    with pytest.raises(NoScopeSetInProvideError):
-        provider.provide(A, provides=B)
-
-    def b() -> int:
-        return 1
-
-    with pytest.raises(NoScopeSetInProvideError):
-        provider.provide(b, provides=B)
-
-
-    with pytest.raises(NoScopeSetInContextError):
-        provider.from_context(b)
-
-
 def test_parse_factory_invalid_hint():
     def foo(self) -> int:
         yield 1
@@ -398,118 +362,3 @@ def test_provide_all_in_class():
 
     fifty = container.get(float)
     assert fifty == 50.0
-
-
-make_factory_by_source = partial(
-    make_factory,
-    provides=None,
-    scope=Scope.REQUEST,
-    cache=True,
-    is_in_class=False,
-    override=False,
-)
-
-
-def test_static_method():
-    with pytest.raises(TypeError):
-        class S1(Provider):
-
-            @provide(scope=Scope.APP)
-            @staticmethod
-            def s() -> AsyncGenerator[None, None]:
-                yield
-
-    with pytest.raises(MissingReturnHintError):
-        class S2(Provider):
-
-            @provide(scope=Scope.APP)
-            @staticmethod
-            def s():
-                yield
-
-    with pytest.raises(MissingHintsError):
-        class S3(Provider):
-
-            @provide(scope=Scope.APP)
-            @staticmethod
-            def s(a):
-                yield
-
-    with pytest.raises(UndefinedTypeAnalysisError):
-        class S4(Provider):
-
-            @provide(scope=Scope.APP)
-            @staticmethod
-            def s(a:"S5"):  #noqa: F821
-                yield
-
-
-def test_no_hints():
-    with pytest.raises(MissingHintsError):
-        class C1(Provider):
-            @provide(scope=Scope.APP)
-            def c(self, a) -> int:
-                return 1
-
-    with pytest.raises(MissingReturnHintError):
-        class C2(Provider):
-            @provide(scope=Scope.APP)
-            def c(self, a: int):
-                return 1
-
-    def c() -> "C4":  #noqa: F821
-        return 1
-
-    with pytest.raises(UndefinedTypeAnalysisError):
-
-        class C3(Provider):
-            cp = provide(source=c)
-
-def test_annotated_factory():
-    assert make_factory_by_source(source=Annotated[A, "Annotated"])
-
-
-def test_self():
-
-    with pytest.warns():
-        class P(Provider):
-
-            @provide(scope=Scope.APP)
-            def a(celph) -> int:  #noqa: N805
-                return 1
-
-
-def foo_aiterable() -> AsyncIterable[NoneType]:
-    yield
-
-
-def foo_aiterator() -> AsyncIterator[int]:
-    yield 1
-
-def foo_agen() -> AsyncGenerator[None, None]:
-    yield
-
-
-async def foo_gen() -> Generator[int, None, None]:
-    yield 1
-
-
-async def foo_iterator() -> Iterator[str]:
-    yield ""
-
-async def foo_iterable() -> Iterable[float]:
-    yield 0
-
-
-@pytest.mark.parametrize("source", [
-    foo_gen, foo_aiterable, foo_aiterator,
-    foo_agen, foo_iterable, foo_iterator,
-])
-def test_factory_error_hints(source):
-    with pytest.raises(TypeError):
-        make_factory_by_source(source=source)
-
-
-def test_not_a_factory():
-    with pytest.raises(NotAFactoryError):
-        make_factory_by_source(source=None)