Test discovery for unittest #50251
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = 'https://github.com/voidspace' closed_at = <Date 2009-05-29.20:44:19.885> created_at = <Date 2009-05-11.21:40:35.814> labels = ['type-feature', 'library'] title = 'Test discovery for unittest' updated_at = <Date 2009-05-29.20:44:19.883> user = 'https://github.com/voidspace'
activity = <Date 2009-05-29.20:44:19.883> actor = 'michael.foord' assignee = 'michael.foord' closed = True closed_date = <Date 2009-05-29.20:44:19.885> closer = 'michael.foord' components = ['Library (Lib)'] creation = <Date 2009-05-11.21:40:35.814> creator = 'michael.foord' dependencies =  files = ['13961', '14052'] hgrepos =  issue_num = 6001 keywords = ['patch', 'needs review'] message_count = 7.0 messages = ['87591', '87616', '88268', '88271', '88434', '88448', '88536'] nosy_count = 4.0 nosy_names = ['gregory.p.smith', 'pitrou', 'benjamin.peterson', 'michael.foord'] pr_nums =  priority = 'normal' resolution = 'accepted' stage = 'patch review' status = 'closed' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue6001' versions = ['Python 2.7', 'Python 3.2']
The text was updated successfully, but these errors were encountered:
Attached is a patch that implements test discovery for unittest.
It includes command line argument handling (awkward manual handling but
python -m unittest discover
If the patch is acceptable then I will write docs. Do I need to make a
Brett Cannon has already looked over the test discovery code (not the
It includes a customization hook both for modules and packages to
Advantage of this: it is simple (easy to extend)
Test discovery is provided through the TestLoader.discover method.
It takes three arguments - start directory, pattern to match test files
The main restriction is that all your tests must be importable from the
(A further restriction is that discovery only currently recognises
The load_tests protocol provides a way for packages and modules to
Iff a test module defines a load_tests function then
An example 'do nothing' implementation of load_tests would be:
def load_tests(loader, tests, pattern): return tests
If a package directory name matches the pattern you pass into discovery
def load_tests(loader, tests, pattern): if pattern is None: return tests return TestSuite(tests, loader.discover(os.path.dirname(os.path.abspath(__file__)), pattern))
(The loader stores the top level directory it was originally called with
Discovery does not follow the __path__ attribute of packages / modules
I have tested this implementation on the importlib tests (as one
Many of the restrictions mentioned here would be very easy to solve in
All I can think of for now...
Updated patch with documentation and fixed command line usage message.
Unless there are objections I intend to check this in in the next few
I've already had feedback from a few folks. The only suggestions so far
The behavior as implemented is a subset of the test discovery provided
The load_tests protocol is an idea already in use by the Bzr test