| 669 | |
| 670 | @requires_test_modules |
| 671 | def run_temp_from_capi(self, script, config='legacy'): |
| 672 | if config is False: |
| 673 | # Force using Py_NewInterpreter(). |
| 674 | run_in_interp = (lambda s, c: _testcapi.run_in_subinterp(s)) |
| 675 | config = None |
| 676 | else: |
| 677 | run_in_interp = _testinternalcapi.run_in_subinterp_with_config |
| 678 | if config is True: |
| 679 | config = 'default' |
| 680 | if isinstance(config, str): |
| 681 | config = _interpreters.new_config(config) |
| 682 | with self.capturing(script) as (wrapped, results): |
| 683 | rc = run_in_interp(wrapped, config) |
| 684 | assert rc == 0, rc |
| 685 | results.raise_if_failed() |
| 686 | return results.stdout |