MCPcopy Index your code
hub / github.com/python/cpython / create_test

Method create_test

Lib/test/test_regrtest.py:600–628  ·  view source on GitHub ↗
(self, name=None, code=None)

Source from the content-addressed store, hash-verified

598 self.addCleanup(os_helper.rmtree, self.tmptestdir)
599
600 def create_test(self, name=None, code=None):
601 if not name:
602 name = 'noop%s' % BaseTestCase.TEST_UNIQUE_ID
603 BaseTestCase.TEST_UNIQUE_ID += 1
604
605 if code is None:
606 code = textwrap.dedent("""
607 import unittest
608
609 class Tests(unittest.TestCase):
610 def test_empty_test(self):
611 pass
612 """)
613
614 # test_regrtest cannot be run twice in parallel because
615 # of setUp() and create_test()
616 name = self.TESTNAME_PREFIX + name
617 path = os.path.join(self.tmptestdir, name + '.py')
618
619 self.addCleanup(os_helper.unlink, path)
620 # Use 'x' mode to ensure that we do not override existing tests
621 try:
622 with open(path, 'x', encoding='utf-8') as fp:
623 fp.write(code)
624 except PermissionError as exc:
625 if not sysconfig.is_python_build():
626 self.skipTest("cannot write %s: %s" % (path, exc))
627 raise
628 return name
629
630 def regex_search(self, regex, output):
631 match = re.search(regex, output, re.MULTILINE)

Callers 15

setUpMethod · 0.80
test_successMethod · 0.80
test_skipMethod · 0.80
test_failing_testMethod · 0.80
test_resourcesMethod · 0.80
test_randomMethod · 0.80
test_fromfileMethod · 0.80
test_interruptedMethod · 0.80
test_slowestMethod · 0.80
test_coverageMethod · 0.80
test_waitMethod · 0.80

Calls 6

addCleanupMethod · 0.80
skipTestMethod · 0.80
openFunction · 0.50
dedentMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected