With Python 2.7 and higher you don't have to write new code or use third-party tools to do this; recursive test execution via the command line is built-in. Put an __init__.py in your test directory and:

python -m unittest discover <test_directory>
# or
python -m unittest discover -s <directory> -p '*_test.py'

You can read more in the python 2.7 or python 3.x unittest documentation.

Answer from Travis Bear on Stack Overflow
🌐
Python
docs.python.org › 3 › library › unittest.html
unittest — Unit testing framework
The script Tools/unittestgui/unittestgui.py in the Python source distribution is a GUI tool for test discovery and execution. This is intended largely for ease of use for those new to unit testing. For production environments it is recommended that tests be driven by a continuous integration system such as Buildbot, Jenkins, GitHub Actions, or AppVeyor. The unittest module provides a rich set of tools for constructing and running tests.
Discussions

Pytest or Unittest in 2020
Hey guys, I´m actually doing my first larger project with python and this brings testing with it. So I never really tested a… More on reddit.com
🌐 r/Python
25
22
March 5, 2020
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
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
People also ask

What is unit testing in Python vs pytest?
pytest is often considered better than unittest for its simpler syntax, advanced features like fixtures, and rich plugin ecosystem. However, unittest is part of Python’s standard library and is widely used for basic testing needs.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › running python unit tests with unittest
Running Python Unit Tests With unittest: A Beginner's Guide
How to write unit tests for Python classes?
To write unit tests for Python classes, you create test methods within a test class that inherits from unittest.TestCase or use pytest directly. Each test method verifies the behavior of specific class methods or properties.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › running python unit tests with unittest
Running Python Unit Tests With unittest: A Beginner's Guide
What is a Python unit test?
A Python unit test is a method for testing individual units of source code, typically functions or methods, to ensure they work as expected. It is used to isolate and verify that each part of the program functions correctly.
🌐
testmuai.com
testmuai.com › testmu ai › learning hub › running python unit tests with unittest
Running Python Unit Tests With unittest: A Beginner's Guide
🌐
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. The unittest module is widely used because: No setup needed as it comes pre-installed in Python. Supports test cases, fixtures, assertions, and test suites. Can discover and run tests across the project.
🌐
Real Python
realpython.com › python-unittest
Python's unittest: Writing Unit Tests for Your Code – Real Python
April 29, 2024 - As an example, run the following command to execute the tests in your test_age.py file: ... $ python -m unittest test_age .........
🌐
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 - The python -m unittest command is used to run unit tests when your test cases are organized into a package or module structure and you want to run all the tests in that package or module.
🌐
Mattermost
mattermost.com › blog › how-to-unit-test-with-python
How to Unit Test with Python - Mattermost
April 14, 2022 - Once in the same folder, we can run our tests using the command python test_my_sum.py. This instructs the command line to use Python to execute the test_my_sum file, where it hits our entry point and is then told to use the unittest test runner.
Find elsewhere
🌐
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 - Using the command-line interface to run unit tests can improve your productivity because it allows you to run multiple files at once: ... The line above will run the discovery mode in unittest that will look for the tests inside the current directory.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-unittest-unit-test-example
Python unittest - unit test example | DigitalOcean
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
🌐
Testmuai
testmuai.com › testmu ai › learning hub › running python unit tests with unittest
Running Python Unit Tests With unittest: A Beginner's Guide
September 7, 2026 - Since the unittest framework comes pre-installed with Python, you'll need to install Python if you haven't already. Download the latest version of Python from the official Python website. After downloading, run the installer and follow the on-screen instructions.
🌐
Python Tutorial
pythontutorial.net › home › python unit testing › organizing code & running unittest
Run Unittest in Python: Organizing Code & Running Unittest
July 9, 2022 - Use the command python -m unittest test_package.test_module.TestClass -v to run a single test class.
🌐
Python Developer's Guide
devguide.python.org › testing › run-write-tests
Running and writing tests
February 20, 2026 - Running: The shortest, simplest way of running the test suite is the following command from the root directory of your checkout (after you have built Python): Unix macOS This works on most macOS sy...
🌐
Better Stack
betterstack.com › community › guides › testing › unittest-guide
A Gentle Introduction to Python's unittest Module | Better Stack Community
Python includes a built-in testing framework called unittest, which allows you to write and run automated tests.
🌐
PäksTech
pakstech.com › blog › python-select-unit-test
Run Selected Python Unit Tests from the Command Line | PäksTech
July 22, 2021 - If you want to run only a smaller subset of tests you need to define the module, class or the single test in the command. Assuming that your tests are located in a module called tests: >> python3 -m unittest tests >> python3 -m unittest tests.test_my_class >> python3 -m unittest tests.test_my_class.TestMyClass >> python3 -m unittest tests.test_my_class.TestMyClass.test_my_method
🌐
Testomat
testomat.io › home › python testing guide: how to write and run unit tests
Python Testing Guide: How to Write and Run Unit Tests
July 2, 2026 - We will walk you through writing your first test, structuring your project, and running test scripts via the command line or even using tools like the command CMD and VS Code. Please note: as we noted on top ⬆️ this framework is included in the Python standard library, so there is no additional setup required. The Unittest testing tool supports some important concepts in realizing the key test functions.
Address: Ul. Koszykarska 27b-26, Kraków
🌐
W3Resource
w3resource.com › python-interview › how-do-you-run-unit-tests-with-unittest.php
Running unit tests with unittest in Python
August 12, 2023 - To run unit tests with unittest, you can use the framework's built-in test runner. The test runner is a command-line tool that discovers and executes the test cases and test methods defined in your Python test modules.
🌐
BrowserStack
browserstack.com › home › guide › understanding unit testing in python
Understanding Unit Testing in Python | BrowserStack
February 24, 2026 - Unit testing in Python is a crucial practice to ensure your code works as intended by testing individual components in isolation. Python’s built-in unittest framework offers a robust way to write, organize, and run these tests efficiently, helping developers catch bugs early and maintain high code quality.
🌐
Octopus Deploy
octopus.com › home › devops › unit testing › unit testing in python
Unit Testing In Python: Quick Tutorial And 4 Best Practices | Octopus Deploy
When we run the script, unittest.main() will run all the test methods in our test class. If a test method passes, it means that the function or method we’re testing behaved as expected under the conditions of the test. Assertions are the heart of any test method. They are the conditions that must be met for a test to pass.
🌐
pytest
docs.pytest.org › en › stable › how-to › unittest.html
How to use unittest-based tests with pytest - pytest documentation
pytest supports running Python unittest-based tests out of the box. It’s meant for leveraging existing unittest-based test suites to use pytest as a test runner and also allow to incrementally adapt the test suite to take full advantage of pytest’s features.
🌐
Python Developer's Guide
devguide.python.org › runtests
Python
You should have been redirected · If not, click here to continue