Running Python unittests from Command Line

This script will allow a Python unittest to be run from the command line. import unittest import testFile suite = unittest.TestLoader().loadTestsFromModule(testFile) unittest.TextTestRunner().run(suite) testFile.py import unittest from fun import add class test_function(unittest.TestCase): def test_one(self): result = add(2,3) self.assertEquals(result, 5) fun.py def add(a,b): return a+b

Simple Python Unit Test

This simple Python unit-test tests two function. The first function adds two numbers and the second function uses list comprehensions to make a list of numbers from to 0 to n which are divisible by m. testFile.py import unittest from add import addition, make_list class test_add_function(unittest.TestCase): def test_for_add(self): result = addition(1, 5) self.assertEqual(result, 6) def…Read More