From a650fc940e9c9db59c19fbe0a4c6a77370d7bd1c Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Tue, 31 Mar 2020 07:34:03 -0400 Subject: [PATCH] New Post --- content/blog/pyunittest.md | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 content/blog/pyunittest.md diff --git a/content/blog/pyunittest.md b/content/blog/pyunittest.md new file mode 100644 index 0000000..9e1b51a --- /dev/null +++ b/content/blog/pyunittest.md @@ -0,0 +1,39 @@ +--- +title: "Quick Python: Unit Testing" +date: 2020-03-31T07:27:47-04:00 +draft: false +tags: ["python"] +--- + +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 +python -m unittest discover +``` + + +