def test_methods_with_no_constraints(self):
        """
        toParallelTargets() returns only module names.
        """
        class NormalTestCase(unittest.TestCase):
            def runTest(self):
                pass

        NormalTestCase.__module__ = self._fake_module_name

        targets = loader.toParallelTargets(NormalTestCase(), [])
        self.assertEqual(targets, ["my_test_module"])
    def test_methods_with_constraints(self):
        """
        toParallelTargets() returns test names when constrained.
        """
        class NormalTestCase(unittest.TestCase):
            def runTest(self):
                pass

        NormalTestCase.__module__ = self._fake_module_name
        full_name = "my_test_module.NormalTestCase.runTest"

        targets = loader.toParallelTargets(NormalTestCase(), [full_name])
        self.assertEqual(targets, [full_name])
 def test_returnIsLoadable(self):
     """
     Results returned by toParallelTargets should be loadable by
     loadTargets(), even if they aren't directly loadable through a package
     relative to the current working directory.
     """
     tests_dir = tempfile.mkdtemp(dir=self.tmpdir)
     # No __init__.py in the directory!
     fh = open(os.path.join(tests_dir, 'test_not_in_pkg.py'), 'w')
     fh.write(dedent(
         """
         import unittest
         class A(unittest.TestCase):
             def testPass(self):
                 pass
         """
         ))
     fh.close()
     # Discover stuff
     suite = loader.loadTargets('.')
     # This should resolve it to the module that's not importable from here
     test = loader.toParallelTargets(suite, [])[0]
     loader.loadTargets(test)