๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ unittest.html
unittest โ€” Unit testing framework
Third-party unittest framework with a lighter-weight syntax for writing tests. For example, assert func(10) == 42. ... An extensive list of Python testing tools including functional testing frameworks and mock object libraries.
๐ŸŒ
Real Python
realpython.com โ€บ python-unittest
Python's unittest: Writing Unit Tests for Your Code โ€“ Real Python
April 29, 2024 - As with many things in Python, you can also create your assert methods to facilitate your test writing process. To do this, you can subclass TestCase and extend the class with new assertion methods. For example, say that you frequently need to check that all the values in a list are integer numbers. In that case, you can create a test case class like the following: ... import unittest class CustomTestCase(unittest.TestCase): def assertAllIntegers(self, values): for value in values: self.assertIsInstance( value, int, )
Discussions

Unittest or Pytest?
pytest is pretty much the de facto standard in the industry, and it's compatible with unittest tests if you want/have to use both. To go even more meta, tox is used to run pytest on multiple versions and platforms. You can't go wrong with either, but pytest generally results in cleaner and more reusable test code. Its fixtures are amazing for reusability. More on reddit.com
๐ŸŒ r/learnpython
7
4
January 6, 2023
Pytest or Unittest in 2020
Iยดm actually doing my first larger project with python and this brings testing with it. So I never really tested a rather larger and complex application before (beside writing some simple unittest for example in Java). More on reddit.com
๐ŸŒ r/Python
25
22
March 5, 2020
Best unit-test practices?

pytest has its own runner/command line so once you have a directory full of tests, you can just run pytest in your terminal and it'll run all your unit tests. That's fairly standard and it picks up unittest style tests as well.

More on reddit.com
๐ŸŒ r/Python
10
1
April 9, 2023
is the unittest important??
Does it spark joy? Actually it does for me. I love seeing a suite of unit tests passing, it gives me confidence that my code is working as it should. If I need to make changes or fix any bugs, I know that a unit test will fail if I break anything. More on reddit.com
๐ŸŒ r/Python
81
47
September 2, 2021
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ unit-testing-python-unittest
Python Unittest Tutorial - GeeksforGeeks
June 5, 2026 - Unit testing checks small pieces of code (like functions or classes) to confirm they work correctly. In Python, this is done with the unittest framework, which is built into the standard library and follows the xUnit style.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-unittest-unit-test-example
Python unittest - unit test example | DigitalOcean
Technical tutorials, Q&A, events โ€” This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
๐ŸŒ
BrowserStack
browserstack.com โ€บ home โ€บ guide โ€บ understanding unit testing in python
Understanding Unit Testing in Python | BrowserStack
February 24, 2026 - To run these test cases, you can use a test runner. For example, executing python -m unittest in the command line will discover and run all the tests in the current directory.
๐ŸŒ
Dataquest
dataquest.io โ€บ home โ€บ blog โ€บ a beginner's guide to unit tests in python
A Beginner's Guide to Unit Tests in Python
April 8, 2025 - Unit tests in Python are for testing small pieces of code, typically a single function, referred to as a unit. Here's how to use them.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ example-unit-test-python
Example Unit Test in Python
In the first two lines of code, you import the unittest module and the module that you want to test. In this example case, that's Python's math module.
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ python-unittest
Unit Testing With Python Unittest - Example & Working - DataFlair
April 24, 2026 - In the following example of Unittest in Python, we will take a simple function that calculates the modulus 3 of a value.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @sachinsoni600517 โ€บ unit-testing-in-python-a-comprehensive-guide-for-beginners-985eec71bb4d
Unit Testing in Python: A Comprehensive Guide for Beginners | by Sachin Soni | Medium
March 2, 2024 - # For functions/Methods python -m unittest <script_name>.<class_name>.<function_name> Example -> python -m unittest test_sample.TestSample.test_add # For Classes python -m unittest <script_name>.<class_name> Example -> python-m unittest test_sample.TestSample
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 2 โ€บ unittest
unittest โ€“ Automated testing framework - Python Module of the Week
For example, import unittest class SimplisticTest(unittest.TestCase): def test(self): self.failUnless(True) if __name__ == '__main__': unittest.main() In this case, the SimplisticTest has a single test() method, which would fail if True is ever False. The easiest way to run unittest tests is ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ unit-testing-in-python
How to Write Unit Tests in Python โ€“ with Example Test Code
November 19, 2024 - For example, Python will raise a ZeroDivisionError if you try to divide any number by zero. You can use the unittest module to test for such errors.
๐ŸŒ
Wellsr
wellsr.com โ€บ python โ€บ unittest-examples-for-testing-python-code
Python unittest Examples for Testing Python Code - wellsr.com
December 29, 2020 - Write the following script in a Python file named ... To run the unit test for testing the functionality of your take_square() function, follow these steps. Make a new .py file with some name in the same folder as the ยท arithmetic.py you made earlier. At the top of the file, youโ€™re going to first import the unittest module.
๐ŸŒ
Tabnine
tabnine.com โ€บ home โ€บ unit testing with python: the basics and a quick tutorial
Unit testing with Python: The basics and a quick tutorial - Tabnine
December 5, 2024 - Before we start writing tests, we first need to understand the structure of a test case in Python. A test case is a single unit of testing. It checks for a specific response to a particular set of inputs. In the unittest framework, a test case is represented by unittest.TestCase instances. To write a test case, we first create a class that inherits from unittest.TestCase. The class can contain methods, where each method represents a single test case. Hereโ€™s an example:
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ guides โ€บ testing โ€บ unittest-guide
A Gentle Introduction to Python's unittest Module | Better Stack Community
Since Python 3.4, Python introduced subtests, which consolidate similar tests into a single method. To make use of subtests, rewrite the contents of test_format_file_size.py with the following code: ... import unittest from src.formatter import format_file_size class TestFormatFileSize(unittest.TestCase): def test_format_file_size(self): """Test format_file_size function for various file sizes""" test_cases = [ (0, "0B"), (1, "1.00 B"), (1024, "1.00 KB"), (1024**2, "1.00 MB"), (1024**3, "1.00 GB"), (1024**4, "1.00 TB"), ] for size, expected_output in test_cases: with self.subTest( f"Input size: {size} - Expected output: {expected_output}" ): self.assertEqual(format_file_size(size), expected_output) if __name__ == "__main__": unittest.main()
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python unit testing โ€บ python unittest
Introduction to Python unittest Framework
July 3, 2022 - Create a class that inherits from the unittest.TestCase class to make a test case. Use the assertEqual() method to test if two values are equal. Use the assertRaises() method in a context manager to test expected exceptions. Use the python -m unittest -v command to run a test.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_module_unittest.asp
Python unittest Module
The unittest module provides a framework for writing and running unit tests in Python.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-unittest-to-write-a-test-case-for-a-function-in-python
How To Use unittest to Write a Test Case for a Function in Python | DigitalOcean
September 30, 2020 - Tests written using the unittest module can help you find bugs in your programs, and prevent regressions from occurring as you change your code over time. Teโ€ฆ
๐ŸŒ
Refraction
refraction.dev โ€บ blog โ€บ unit-testing-python-guide-beginners
Unit Testing in Python โ€” A Step-by-Step Guide for Beginners | Refraction
March 10, 2026 - The unittest framework comes pre-installed with Python, so there's no need to install it separately. ... A test case is a set of conditions or inputs that determine whether a unit of code is working correctly. In unittest, a test case is created by subclassing the TestCase class. Here's an example: