= PyUnit = PyUnit is an easy way to create unit testing programs and UnitTests with Python. (Note that docs.python.org uses the name "unittest", which is also the module name.) == Basic Example == Here's a basic example, making use of standard PyUnit conventions. {{{#!python import unittest from foobarbaz import Foo # code from module you're testing class SimpleTestCase(unittest.TestCase): def setUp(self): """Call before every test case.""" self.foo = Foo() self.file = open( "blah", "r" ) def tearDown(self): """Call after every test case.""" self.file.close() def testA(self): """Test case A. note that all test method names must begin with 'test.'""" assert foo.bar() == 543, "bar() not calculating values correctly" def testB(self): """test case B""" assert foo+foo == 34, "can't add Foo instances" def testC(self): """test case C""" assert foo.baz() == "blah", "baz() not returning blah correctly" class OtherTestCase(unittest.TestCase): def setUp(self): blah_blah_blah() def tearDown(self): blah_blah_blah() def testBlah(self): assert self.blahblah == "blah", "blah isn't blahing blahing correctly" if __name__ == "__main__": unittest.main() # run all tests }}} For more details, see [[http://pyunit.sourceforge.net/pyunit.html|the PyUnit manual]] and "unittest" at [[https://docs.python.org/3.6/library/unittest.html|docs.python.org]]. == See Also == * [[http://pyunit.sourceforge.net|SourceForge.net PyUnit site]] * [[http://pyunit.sourceforge.net/pyunit.html#USING|Using Section of the PyUnit manual]] * [[https://www.cmi.ac.in/~madhavan/courses/prog2-2012/docs/diveintopython3/unit-testing.html|Dive into Python]] chapter on unit testing * UnitTests ---- = Discussion = . (none yet!)