Skip to content

Instantly share code, notes, and snippets.

@Curt-Park
Last active January 4, 2024 07:32
Show Gist options
  • Save Curt-Park/a51e47d5276b433db122ca7819fee0a7 to your computer and use it in GitHub Desktop.
Save Curt-Park/a51e47d5276b433db122ca7819fee0a7 to your computer and use it in GitHub Desktop.
unit test generation with pynguin
# Pynguin is now able to generate assertions for simple data types (int, float, str, and bool),
# as well as checks for None return values.
# https://pynguin.readthedocs.io/en/latest/index.html
def fibonacci(n: int) -> int:
assert n >= 0
a, b = 1, 0
for _ in range(n):
a, b = a + b, a
return a
# usage: `$ make utest MODULE_NAME=fibonacci`
utest:
if [ ! -d "test" ]; then mkdir test; fi
pynguin --algorithm RANDOM --project_path . --output_path test --module_name ${MODULE_NAME}
# usage: `$ make run-utest`
run-utest:
env PYTHONPATH=. pytest test --verbose --cov . --cov-report=html --cov-report=term-missing
# usage: `$ make show-cov MODULE_NAME=fibonacci`
show-cov:
open -a "Google Chrome" htmlcov/${MODULE_NAME}_py.html
# pip install -r requirements.txt
pynguin == 0.8.0
pytest == 6.2.3
pytest-cov == 2.11.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment