Skip to content

Commit 6441507

Browse files
authored
Enforce 100% code coverage in tests (#283)
1 parent 1575cbb commit 6441507

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

noxfile.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ def test(s: Session) -> None:
1616
f"--python={s.virtualenv.location}",
1717
env={"UV_PROJECT_ENVIRONMENT": s.virtualenv.location},
1818
)
19-
s.run("pytest", "--cov=fact", "--cov-report=html", "--cov-report=term", "tests", *s.posargs)
19+
s.run(
20+
"pytest",
21+
"--cov=fact",
22+
"--cov-report=html",
23+
"--cov-report=term",
24+
"--cov-fail-under=100",
25+
"tests",
26+
*s.posargs,
27+
)
2028

2129

2230
# For some sessions, set venv_backend="none" to simply execute scripts within the existing

src/fact/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ def main(n: Annotated[int, Argument(min=0, help="The input n of fact(n)")]) -> N
1818

1919

2020
# Allow the script to be run standalone (useful during development).
21-
if __name__ == "__main__":
21+
if __name__ == "__main__": # pragma: no branch
2222
app()

tests/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import subprocess
2+
3+
4+
def test_main() -> None:
5+
"""Test the main function of the CLI."""
6+
7+
# Run the CLI command
8+
result = subprocess.run(
9+
["python", "-m", "fact.cli", "5"],
10+
capture_output=True,
11+
text=True,
12+
)
13+
14+
# Check the output
15+
assert result.returncode == 0
16+
assert "fact(5) = 120" in result.stdout
File renamed without changes.

0 commit comments

Comments
 (0)