Skip to content

Commit 567b837

Browse files
Properly use test deps in is_used heuristic
1 parent 486072e commit 567b837

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/usethis/_tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def is_used(self) -> bool:
124124
for dep in self.get_dev_deps(unconditional=True):
125125
if is_dep_in_any_group(dep):
126126
return True
127+
for dep in self.get_test_deps(unconditional=True):
128+
if is_dep_in_any_group(dep):
129+
return True
127130

128131
return False
129132

tests/usethis/test_usethis_tool.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ def name(self) -> str:
4040
return "my_tool"
4141

4242
def get_dev_deps(self, *, unconditional: bool = False) -> list[Dependency]:
43-
return [
43+
deps = [
4444
Dependency(name=self.name),
4545
Dependency(name="black"),
4646
Dependency(name="flake8"),
4747
]
48+
if unconditional:
49+
deps.append(Dependency(name="pytest"))
50+
return deps
4851

4952
def print_how_to_use(self) -> None:
5053
box_print("How to use my_tool")
5154

52-
def get_extra_dev_deps(self) -> list[Dependency]:
53-
return [Dependency(name="pytest")]
54-
5555
def get_pre_commit_repos(self) -> list[LocalRepo | UriRepo]:
5656
return [
5757
UriRepo(
@@ -249,7 +249,25 @@ def test_empty(self, uv_init_dir: Path):
249249
# Assert
250250
assert not result
251251

252-
def test_extra_dev_deps(self, uv_init_dir: Path):
252+
def test_dev_deps(self, uv_init_dir: Path):
253+
# Arrange
254+
tool = MyTool()
255+
256+
with change_cwd(uv_init_dir):
257+
add_deps_to_group(
258+
[
259+
Dependency(name="black"),
260+
],
261+
"dev",
262+
)
263+
264+
# Act
265+
result = tool.is_used()
266+
267+
# Assert
268+
assert result
269+
270+
def test_test_deps(self, uv_init_dir: Path):
253271
# Arrange
254272
tool = MyTool()
255273

0 commit comments

Comments
 (0)