Skip to content

Commit 5b7ab1d

Browse files
authored
A case study... (#194)
* Use a third-party dependency in the sample A case study of "test it if you expect it to work". * Add types-requests for mypy * Install requirements.txt as expected The conclusion of the case study.
1 parent 1e052c9 commit 5b7ab1d

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

noxfile.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def run_tests_with_coverage(session: nox.Session) -> None:
7171
"""Run pytest with coverage, outputs console report and json."""
7272
print_standard_logs(session)
7373

74-
session.install(".", "-r", f"{REQUIREMENTS_PATH}/requirements-test.txt")
74+
session.install(".")
75+
session.install("-r", f"{REQUIREMENTS_PATH}/requirements.txt")
76+
session.install("-r", f"{REQUIREMENTS_PATH}/requirements-test.txt")
7577

7678
coverage = partial(session.run, "python", "-m", "coverage")
7779

@@ -103,7 +105,9 @@ def run_linters_and_formatters(session: nox.Session) -> None:
103105
"""Run code formatters, linters, and type checking against all files."""
104106
print_standard_logs(session)
105107

106-
session.install(".", "-r", f"{REQUIREMENTS_PATH}/requirements-dev.txt")
108+
session.install(".")
109+
session.install("-r", f"{REQUIREMENTS_PATH}/requirements.txt")
110+
session.install("-r", f"{REQUIREMENTS_PATH}/requirements-dev.txt")
107111

108112
python = partial(session.run, "python", "-m")
109113

requirements/requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ isort
1212

1313
# type checking
1414
mypy
15+
types-requests

src/module_name/sample.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import requests
6+
57

68
def main() -> bool:
79
"""Main"""
@@ -17,3 +19,8 @@ def squared(value: int) -> int:
1719
def isodd(value: int) -> bool:
1820
"""Return if value is odd."""
1921
return bool(value % 2)
22+
23+
24+
def health_check() -> bool:
25+
"""Returns true when github.com is accessible."""
26+
return requests.get("https://github.com").ok

tests/test_sample.py renamed to tests/sample_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from module_name import sample
88

99

10-
def test_main():
10+
def test_main() -> None:
1111
"""Main test"""
1212
assert sample.main()
1313

@@ -20,5 +20,9 @@ def test_main():
2020
(16, 256),
2121
),
2222
)
23-
def test_squared(value_in, expected):
23+
def test_squared(value_in: int, expected: int) -> None:
2424
assert sample.squared(value_in) == expected
25+
26+
27+
def test_health_check() -> None:
28+
assert sample.health_check()

0 commit comments

Comments
 (0)