(self, argv, *, cwd=None)
| 83 | |
| 84 | @support.requires_subprocess() |
| 85 | def run_python(self, argv, *, cwd=None): |
| 86 | # This method is inspired by |
| 87 | # EmbeddingTestsMixin.run_embedded_interpreter() in test_embed.py. |
| 88 | import shlex |
| 89 | import subprocess |
| 90 | if isinstance(argv, str): |
| 91 | argv = shlex.split(argv) |
| 92 | argv = [sys.executable, *argv] |
| 93 | try: |
| 94 | proc = subprocess.run( |
| 95 | argv, |
| 96 | cwd=cwd, |
| 97 | capture_output=True, |
| 98 | text=True, |
| 99 | ) |
| 100 | except Exception as exc: |
| 101 | self.debug(f'# cmd: {shlex.join(argv)}') |
| 102 | if isinstance(exc, FileNotFoundError) and not exc.filename: |
| 103 | if os.path.exists(argv[0]): |
| 104 | exists = 'exists' |
| 105 | else: |
| 106 | exists = 'does not exist' |
| 107 | self.debug(f'{argv[0]} {exists}') |
| 108 | raise # re-raise |
| 109 | assert proc.stderr == '' or proc.returncode != 0, proc.stderr |
| 110 | if proc.returncode != 0 and support.verbose: |
| 111 | self.debug(f'# python3 {shlex.join(argv[1:])} failed:') |
| 112 | self.debug(proc.stdout, header='stdout') |
| 113 | self.debug(proc.stderr, header='stderr') |
| 114 | self.assertEqual(proc.returncode, 0) |
| 115 | self.assertEqual(proc.stderr, '') |
| 116 | return proc.stdout |
| 117 | |
| 118 | def test_sys_path_0(self): |
| 119 | # The main interpreter's sys.path[0] should be used by subinterpreters. |
no test coverage detected