diff --git a/poetry/core/packages/dependency_group.py b/poetry/core/packages/dependency_group.py index 65e26d603..d92e26e49 100644 --- a/poetry/core/packages/dependency_group.py +++ b/poetry/core/packages/dependency_group.py @@ -26,13 +26,13 @@ def is_optional(self) -> bool: def add_dependency(self, dependency: "DependencyTypes") -> None: self._dependencies.append(dependency) - def remove_dependency(self, name: "str") -> None: + def remove_dependency(self, name: str) -> None: from poetry.core.utils.helpers import canonicalize_name name = canonicalize_name(name) dependencies = [] - for dependency in dependencies: + for dependency in self.dependencies: if dependency.name == name: continue diff --git a/tests/packages/test_dependency_group.py b/tests/packages/test_dependency_group.py new file mode 100644 index 000000000..f6412cc8a --- /dev/null +++ b/tests/packages/test_dependency_group.py @@ -0,0 +1,24 @@ +from poetry.core.packages.dependency import Dependency +from poetry.core.packages.dependency_group import DependencyGroup + + +def test_dependency_group_remove_dependency(): + group = DependencyGroup(name="linter") + group.add_dependency(Dependency(name="black", constraint="*")) + group.add_dependency(Dependency(name="isort", constraint="*")) + group.add_dependency(Dependency(name="flake8", constraint="*")) + + assert {dependency.name for dependency in group.dependencies} == { + "black", + "isort", + "flake8", + } + + group.remove_dependency("isort") + assert {dependency.name for dependency in group.dependencies} == {"black", "flake8"} + + group.remove_dependency("black") + assert {dependency.name for dependency in group.dependencies} == {"flake8"} + + group.remove_dependency("flake8") + assert {dependency.name for dependency in group.dependencies} == set()