This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients brett.cannon, eric.snow
Date 2014-05-13.18:55:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Right now to run importlib tests you can do either of the following:

./python -m tests test_importlib
./python -m tests.test_importlib

Both make use of the regrtest infrastructure.  For test submodules the commands are similar:

./python -m tests test_importlib.test_api
./python -m tests.test_importlib.test_api

You can also use unittest directly when testing specific test modules:

./python -m unittest tests.test_importlib.test_api
./python -m unittest tests.test_importlib.test_api.Source_ReloadTests.test_reload_location_changed

However, currently you cannot use unittest directly with a test package:

./python -m unittest tests.test_importlib
./python -m unittest tests.test_importlib.source

It would be nice to be able to do so, rather than switching back and forth between the unittest CLI and the regrtest CLI.

The change to do so is relatively straight-forward using the "load_tests" protocol*.  Just add the following to the of the test packages:

 def load_tests(loader, tests, pattern):
     from test import TEST_HOME_DIR as topdir
     startdir = os.path.dirname(__name__)
     pkgtests =, pattern or 'test*.py', topdir)
     return tests

The boilerplate could even be moved to as a factory function:

 def make_load_tests(modfilename):
     from test import TEST_HOME_DIR as topdir
     startdir = os.path.dirname(modfilename)
     def load_tests(loader, tests, pattern):
         pkgtests =, pattern or 'test*.py', topdir)
         return tests
     return load_tests

In the test package

  load_tests = support.make_load_tests(__name__)

Then using unittest directly with an importlib test package will work as expected.  This is also something that could readily apply to any other test packages in the suite, which is why the factory function in makes sense.

Date User Action Args
2014-05-13 18:55:58eric.snowsetrecipients: + eric.snow, brett.cannon
2014-05-13 18:55:58eric.snowsetmessageid: <>
2014-05-13 18:55:58eric.snowlinkissue21500 messages
2014-05-13 18:55:57eric.snowcreate