From 0362ffbb5a3f14964b6c59cc9d9c04aba7d9ccfe Mon Sep 17 00:00:00 2001 From: finswimmer Date: Fri, 12 Nov 2021 03:16:51 +0100 Subject: [PATCH] Fix: Remove only targetted package (#220) Fix an issue where all default dependencies were removed instead of just the selected one (fixes #4632) --- poetry/core/packages/dependency_group.py | 4 ++-- tests/packages/test_dependency_group.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/packages/test_dependency_group.py 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()