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 <1400007358.12.0.940641548905.issue21500@psf.upfronthosting.co.za>
In-reply-to
Content
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 __init__.py of the test packages:

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

The boilerplate could even be moved to tests.support 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 = loader.discover(startdir, pattern or 'test*.py', topdir)
         tests.addTests(pkgtests)
         return tests
     return load_tests

In the test package __init__.py:

  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 test.support makes sense.

* https://docs.python.org/2/library/unittest.html#load-tests-protocol
History
Date User Action Args
2014-05-13 18:55:58eric.snowsetrecipients: + eric.snow, brett.cannon
2014-05-13 18:55:58eric.snowsetmessageid: <1400007358.12.0.940641548905.issue21500@psf.upfronthosting.co.za>
2014-05-13 18:55:58eric.snowlinkissue21500 messages
2014-05-13 18:55:57eric.snowcreate