(self, name=None, code=None)
| 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) |
no test coverage detected