Created
March 6, 2021 10:33
-
-
Save gamorales/e843e0a059a8d6aa8e53608623774546 to your computer and use it in GitHub Desktop.
Test coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(): | |
return 5 | |
def main(): | |
x = foo() | |
print(x) | |
if __name__ == '__main__': # pragma: no cover | |
main() | |
## test code | |
# To test: | |
# pip install pytest | |
# pytest script.py | |
# To test with coverage: | |
# put this file (script.py) in a directory by itself, say foo | |
# then from the parent directory of foo: | |
# pip install pytest-cov | |
# pytest --cov=foo foo/script.py | |
# To show missing lines | |
# pytest --cov=foo --cov-report=term-missing foo/script.py | |
def test_foo(): | |
assert foo() == 5 | |
def test_main(capsys): | |
main() | |
captured = capsys.readouterr() | |
assert captured.out == "5\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment