diff --git a/tests/providers/test_alias.py b/tests/providers/test_alias.py index f246e20..d5a6c5f 100644 --- a/tests/providers/test_alias.py +++ b/tests/providers/test_alias.py @@ -32,12 +32,6 @@ def test_alias_delegates_to_source() -> None: assert concrete is abstract -def test_alias_resolve_provider() -> None: - container = Container(groups=[MyGroup]) - instance = container.resolve_provider(MyGroup.abstract_repo) - assert isinstance(instance, PostgresRepository) - - def test_alias_without_caching_returns_fresh_instance_per_call() -> None: class G(Group): repo = providers.Factory(creator=PostgresRepository) diff --git a/tests/providers/test_factory.py b/tests/providers/test_factory.py index e561a3d..deb9d87 100644 --- a/tests/providers/test_factory.py +++ b/tests/providers/test_factory.py @@ -39,7 +39,6 @@ class MyGroup(Group): creator=SimpleCreator, skip_creator_parsing=True, bound_type=None ) func_with_union_factory = providers.Factory(creator=func_with_union, bound_type=None) - func_with_broken_annotation = providers.Factory(creator=func_with_broken_annotation, bound_type=None) request_factory = providers.Factory(scope=Scope.REQUEST, creator=DependentCreator) request_factory_with_di_container = providers.Factory(scope=Scope.REQUEST, creator=AnotherCreator) @@ -72,13 +71,17 @@ def test_app_factory_unresolvable() -> None: def test_func_with_union_factory() -> None: app_container = Container(groups=[MyGroup]) instance1 = app_container.resolve_provider(MyGroup.func_with_union_factory) - assert instance1 + assert instance1 == str(SimpleCreator(dep1="original")) def test_func_with_broken_annotation() -> None: - app_container = Container(groups=[MyGroup]) + with pytest.warns(UserWarning, match="Failed to resolve type hints"): + factory = providers.Factory(creator=func_with_broken_annotation, bound_type=None) + + app_container = Container() + app_container.providers_registry.add_providers(factory) with pytest.raises(ArgumentResolutionError, match="Argument dep1 of type None cannot be resolved"): - app_container.resolve_provider(MyGroup.func_with_broken_annotation) + app_container.resolve_provider(factory) def test_request_factory() -> None: diff --git a/tests/test_container.py b/tests/test_container.py index 3393412..00f4660 100644 --- a/tests/test_container.py +++ b/tests/test_container.py @@ -62,7 +62,7 @@ def test_container_resolve_missing_provider() -> None: ProviderNotRegisteredError, match=r"Provider of type is not registered in providers registry.", ) as exc: - assert app_container.resolve(str) is None + app_container.resolve(str) assert exc.value.provider_type is str @@ -143,7 +143,9 @@ def test_validate_detects_cycle() -> None: container.validate() [issue] = exc.value.errors assert isinstance(issue, CircularDependencyError) - assert issue.cycle_path == ["CycleA", "CycleB", "CycleA"] + cycle = issue.cycle_path + assert cycle[0] == cycle[-1] + assert set(cycle) == {"CycleA", "CycleB"} def test_validate_passes_for_valid_graph() -> None: