This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
python_cookbook [2019/03/05 09:49] mantis [Unit Tests] |
python_cookbook [2019/03/05 09:51] (current) mantis [Testing] |
||
---|---|---|---|
Line 1855: | Line 1855: | ||
====== Testing ====== | ====== Testing ====== | ||
+ | |||
+ | ===== pytest ===== | ||
+ | |||
+ | https://docs.pytest.org/en/latest/example/ | ||
+ | |||
+ | https://docs.pytest.org/en/latest/goodpractices.html#choosing-a-test-layout-import-rules | ||
+ | |||
===== unittest ===== | ===== unittest ===== | ||
Line 1862: | Line 1869: | ||
* http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html the nutshell | * http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html the nutshell | ||
- | ===== Basics ===== | + | ==== Basics ==== |
<code python> | <code python> | ||
import unittest | import unittest | ||
Line 1879: | Line 1886: | ||
</code> | </code> | ||
- | ===== classwide Setup and teardown ===== | + | ==== classwide Setup and teardown ==== |
There are two class methods that are called before/after tests in an individual class run. | There are two class methods that are called before/after tests in an individual class run. | ||
Line 1907: | Line 1914: | ||
</code> | </code> | ||
- | ===== Test for exceptions ===== | + | ==== Test for exceptions ==== |
Since [[http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises|python 2.7]] this is best done by using the context manager returned by unittest.assertRaises() | Since [[http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises|python 2.7]] this is best done by using the context manager returned by unittest.assertRaises() |