Pattern – running a subset of tests
We already saw a simple way of running a subset of tests by simply specifying the module or test class on the command line, as shown in the following:
python -m unittest stock_alerter.tests.test_stock python -m unittest stock_alerter.tests.test_stock.StockTest
This works for the common case of when we want to run a subset based on the module. What if we want to run tests based on some other parameter? Maybe we want to run a set of basic smoke tests, or we want to run only integration tests, or we want to skip tests when running on a specific platform or Python version.
The unittest
module allows us to create test suites. A test suite is a collection of test classes that are run. By default, unittest
performs an autodiscovery for tests and internally creates a test suite with all the tests that match the discovery pattern. However, we can also manually create different test suites and run them.
Test suites are created using the unittest.TestSuite
class. The...