2020-03-31 07:34:03 -04:00
---
title: "Quick Python: Unit Testing"
date: 2020-03-31T07:27:47-04:00
draft: false
2022-01-02 14:24:29 -05:00
tags: ["Python", "Testing"]
2023-01-05 14:04:45 -05:00
medium_enabled: true
2020-03-31 07:34:03 -04:00
---
Python has a great built-in [unit test ](https://docs.python.org/3.7/library/unittest.html ) framework. This post will give a skeleton for how to format the files in your `tests` directory.
Example `tests/test_basic.py`
```python
import unittest
class Tester(unittest.TestCase):
def setUp(self):
"""To Run Before Every Test Case"""
pass
def tearDown(self):
"""To Run After Every Test Case"""
pass
def test_something(self):
"""A Test Case"""
self.assertEqual(True, True)
if __name__ == '__main__':
unittest.main()
```
To auto-discover and run your tests
```bash
2020-05-18 13:56:57 -04:00
python -m unittest discover -s tests
2020-03-31 07:34:03 -04:00
```