New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test discovery for unittest #50251
Comments
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... |
The usage information in TestProgram in this patch is not correct. If __name__ != __main__ it should be unchanged - the new usage message |
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 |
Georg Brandl has pointed out various minor issues in the docs (and |
Would you like to upload your patch to Rietveld? |
Committed in revision 73027. |
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: