[issue7559] TestLoader.loadTestsFromName swallows import errors

Chris Jerdonek report at bugs.python.org
Mon Jun 4 17:20:38 CEST 2012


Chris Jerdonek <chris.jerdonek at gmail.com> added the comment:

Because we don't know if the rest of the test code will adhere to this, we might want to consider clearing the cache before each test as well.

Alternatively, we could avoid having to call importlib.invalidate_caches() at all (and having to think about for which tests it is necessary) if we do each test in a different directory and with a different name for the test package.  We could do the former as follows:

    with support.temp_cwd(support.TESTFN):
        dir_name = self.id().split('.')[-1]  # test method name
        with support.temp_cwd(dir_name) as cwd:
            with support.DirsOnSysPath(cwd):
                # Create package and run test.

An approach like this might be less prone to issues that are hard to troubleshoot.  I verified that it works.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7559>
_______________________________________


More information about the Python-bugs-list mailing list