Category Archives: Python unittest

Python testing with unittest module | Testing mathematical operations

The unittest module is part of Python’s standard library and it is very popular when it comes to testing Python code. You need two files (preferably placed in the same directory), one file that contains the code that is tested and another file with the code that tests the code of the first file.

My first file is named and it contains basic functions I am going to test. The second file is named and it is going to contain the testing code.

I am referring to this documentation when writing the tests on this page:

Testing Python’s mathematical operators with unittest module

In order to start testing I have created the following basic functions in my file.

def addition(a, b):
	return a + b

def subtraction(a, b):
	return a - b

def multiplication(a, b):
	return a * b

def division(a, b):
	if b == 0:
		raise ValueError("Can't divide by zero!")
	return a / b

Continue reading