Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix issue with DEP004 being raised incorrectly if a dependency is bot…
…h a regular and a dev dependency
  • Loading branch information
fpgmaas committed May 9, 2023
commit c7c39b7b3f48aba7fa6c1f9b9ac94d99549aba86
4 changes: 3 additions & 1 deletion deptry/issues_finder/misplaced_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def find(self) -> list[Violation]:
return misplaced_dev_dependencies

def _is_development_dependency(self, module: Module, corresponding_package_name: str) -> bool:
if not module.is_dev_dependency:
# Module can both be a regular and a development dependency.
# Only continue if module is ONLY a dev dependency.
if not module.is_dev_dependency or module.is_dependency:
return False

if module.name in self.ignored_modules:
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/issues_finder/test_misplaced_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ def test_simple() -> None:
assert MisplacedDevDependenciesFinder(modules_locations, dependencies).find() == [
MisplacedDevDependencyViolation(module_foo, location) for location in module_foo_locations
]


def test_regular_and_dev_dependency() -> None:
"""
If a dependency is both a regular and a development dependency, no error 'misplaced dev dependency' violation
should be detected if it is used in the code base.
"""

dependencies = [Dependency("foo", Path("pyproject.toml"))]

module_foo_locations = [Location(Path("foo.py"), 1, 2)]
module_foo = Module("foo", dev_top_levels=["foo"], is_dev_dependency=True, is_dependency=True)

modules_locations = [ModuleLocations(module_foo, module_foo_locations)]

assert not MisplacedDevDependenciesFinder(modules_locations, dependencies).find()