Earlier we said, for different file cases, we can use case load by addTest () to a test suite (TestSuite) to uniform implementation, for a small number of documents to do so no problem, but if there are tens of hundreds of use cases files, to do so would a waste of time.
The discover unittest () method can be bulk loaded with the Example
discover(start_dir, pattern='test*.py', top_level_dir=None)
- start_dir: test name or test module directory
- pattern = 'test * .py': represented by way of example matching file names, matching here is the type of test .py beginning of the file, which matches any character *
- top_level_dir: test module top-level directory
Code:
import unittest if __name__ == "__main__": # Test directory test_dir = r"D:\Git\Test_Framework\test_case" # Load test discover = unittest.defaultTestLoader.discover (test_dir, 'test * .py') # return value is a test suite runner = unittest.TextTestRunner(verbosity=2) runner.run(discover)