29 lines
732 B
Markdown
29 lines
732 B
Markdown
|
# Testing functions
|
||
|
|
||
|
|
||
|
Once you have created your definitions you want to put them in a main class and have something to display if the functions passed. For example:
|
||
|
|
||
|
|
||
|
```
|
||
|
def test_sum():
|
||
|
assert sum([1, 2, 3]) == 6, "Should be 6"
|
||
|
|
||
|
def test_sum_tuple():
|
||
|
assert sum((1, 2, 2)) == 6, "Should be 6"
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
test_sum()
|
||
|
test_sum_tuple()
|
||
|
print("Everything passed")
|
||
|
```
|
||
|
|
||
|
|
||
|
This [site](https://realpython.com/python-testing/) has several differnt testing methods that can be used with python. Unittest, nose, and [pytest](https://docs.pytest.org/en/latest/) are the most commonly used.
|
||
|
|
||
|
How to execute pytest:
|
||
|
https://docs.pytest.org/en/latest/
|
||
|
|
||
|
## testing paradigms in python
|
||
|
- tox
|
||
|
- pytest
|
||
|
-
|