Skip to content

Instantly share code, notes, and snippets.

@OmarIthawi
Created April 4, 2024 12:47
Show Gist options
  • Save OmarIthawi/f92a452d3d193d6bc7c68a3eb7532491 to your computer and use it in GitHub Desktop.
Save OmarIthawi/f92a452d3d193d6bc7c68a3eb7532491 to your computer and use it in GitHub Desktop.
Python testing tutorial
"""
Run with either:
- $ python testing_example.py
OR
- $ pytest -v testing_example.py
"""
def sum_numbers(a, b):
result = a + b
print(f'DEBUG: {a} + {b} = {result}')
return result
def test_sum_numbers_positive():
"""
Something goes here.
"""
assert sum_numbers(1, 2) == 3
def test_sum_numbers_zero():
assert sum_numbers(0, 0) == 0
def test_sum_numbers_one_with_zero():
assert sum_numbers(1, 0) == 1
def test_sum_numbers_flipped_one_with_zero():
assert sum_numbers(0, 1) == 1
if __name__ == '__main__':
# Runs if `pytest` isn't used
test_sum_numbers_positive()
test_sum_numbers_zero()
test_sum_numbers_one_with_zero()
test_sum_numbers_flipped_one_with_zero()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment