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

Method run_embedded_interpreter

Lib/test/test_embed.py:108–141  ·  view source on GitHub ↗

Runs a test in the embedded interpreter

(self, *args, env=None,
                                 timeout=None, returncode=0, input=None,
                                 cwd=None)

Source from the content-addressed store, hash-verified

106 os.chdir(self.oldcwd)
107
108 def run_embedded_interpreter(self, *args, env=None,
109 timeout=None, returncode=0, input=None,
110 cwd=None):
111 """Runs a test in the embedded interpreter"""
112 cmd = [self.test_exe]
113 cmd.extend(args)
114 if env is not None and MS_WINDOWS:
115 # Windows requires at least the SYSTEMROOT environment variable to
116 # start Python.
117 env = env.copy()
118 env['SYSTEMROOT'] = os.environ['SYSTEMROOT']
119
120 p = subprocess.Popen(cmd,
121 stdout=subprocess.PIPE,
122 stderr=subprocess.PIPE,
123 universal_newlines=True,
124 env=env,
125 cwd=cwd)
126 try:
127 (out, err) = p.communicate(input=input, timeout=timeout)
128 except:
129 p.terminate()
130 p.wait()
131 raise
132 if p.returncode != returncode and support.verbose:
133 print(f"--- {cmd} failed ---")
134 print(f"stdout:\n{out}")
135 print(f"stderr:\n{err}")
136 print("------")
137
138 self.assertEqual(p.returncode, returncode,
139 "bad returncode %d, stderr is %r" %
140 (p.returncode, err))
141 return out, err
142
143 def run_repeated_init_and_subinterpreters(self):
144 out, err = self.run_embedded_interpreter("test_repeated_init_and_subinterpreters")

Calls 6

communicateMethod · 0.95
terminateMethod · 0.95
waitMethod · 0.95
extendMethod · 0.45
copyMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected