예제 #1
0
 def test_moduleImportFailureIgnored(self):
     """
     toProtoTestList() does not raise errors when doing completions
     """
     suite = MagicMock()
     suite.__class__.__name__ = str('ModuleImportFailure')
     suite.__str__.return_value = "exception_method other_stuff"
     suite.exception_method.side_effect = AttributeError
     self.assertEqual(loader.toProtoTestList(suite, doing_completions=True), [])
예제 #2
0
 def test_BigDirWithAbsoluteImports(self):
     """
     Big dir discovers tests and doesn't crash on absolute import
     """
     sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
     pkg_name = os.path.basename(sub_tmpdir)
     # Child setup
     # pkg/__init__.py
     fh = open(os.path.join(sub_tmpdir, '__init__.py'), 'w')
     fh.write('\n')
     fh.close()
     # pkg/target_module.py
     fh = open(os.path.join(sub_tmpdir, 'target_module.py'), 'w')
     fh.write('a = 1\n')
     fh.close()
     # pkg/test/__init__.py
     os.mkdir(os.path.join(sub_tmpdir, 'test'))
     fh = open(os.path.join(sub_tmpdir, 'test', '__init__.py'), 'w')
     fh.write('\n')
     fh.close()
     # pkg/test/test_target_module.py
     fh = open(os.path.join(sub_tmpdir, 'test', 'test_target_module.py'), 'w')
     fh.write(dedent(
         """
         import unittest
         import {}.target_module
         class A(unittest.TestCase):
             def testPass(self):
                 pass
         """.format(pkg_name)))
     fh.close()
     # Load the tests
     os.chdir(self.tmpdir)
     test_suite = loader.loadTargets(pkg_name)
     self.assertEqual(test_suite.countTestCases(), 1)
     # Dotted name should start with the package!
     self.assertEqual(
             pkg_name + '.test.test_target_module.A.testPass',
             loader.toProtoTestList(test_suite)[0].dotted_name)