Return result of running pytest in-process, providing a similar interface to what self.runpytest() provides.
(
self, *args: str | os.PathLike[str], **kwargs: Any
)
| 1165 | finalizer() |
| 1166 | |
| 1167 | def runpytest_inprocess( |
| 1168 | self, *args: str | os.PathLike[str], **kwargs: Any |
| 1169 | ) -> RunResult: |
| 1170 | """Return result of running pytest in-process, providing a similar |
| 1171 | interface to what self.runpytest() provides.""" |
| 1172 | syspathinsert = kwargs.pop("syspathinsert", False) |
| 1173 | |
| 1174 | if syspathinsert: |
| 1175 | self.syspathinsert() |
| 1176 | instant = timing.Instant() |
| 1177 | capture = _get_multicapture("sys") |
| 1178 | capture.start_capturing() |
| 1179 | try: |
| 1180 | try: |
| 1181 | reprec = self.inline_run(*args, **kwargs) |
| 1182 | except SystemExit as e: |
| 1183 | ret = e.args[0] |
| 1184 | try: |
| 1185 | ret = ExitCode(e.args[0]) |
| 1186 | except ValueError: |
| 1187 | pass |
| 1188 | |
| 1189 | class reprec: # type: ignore |
| 1190 | ret = ret |
| 1191 | |
| 1192 | except Exception: |
| 1193 | traceback.print_exc() |
| 1194 | |
| 1195 | class reprec: # type: ignore |
| 1196 | ret = ExitCode(3) |
| 1197 | |
| 1198 | finally: |
| 1199 | out, err = capture.readouterr() |
| 1200 | capture.stop_capturing() |
| 1201 | sys.stdout.write(out) |
| 1202 | sys.stderr.write(err) |
| 1203 | |
| 1204 | assert reprec.ret is not None |
| 1205 | res = RunResult( |
| 1206 | reprec.ret, out.splitlines(), err.splitlines(), instant.elapsed().seconds |
| 1207 | ) |
| 1208 | res.reprec = reprec # type: ignore |
| 1209 | return res |
| 1210 | |
| 1211 | def runpytest(self, *args: str | os.PathLike[str], **kwargs: Any) -> RunResult: |
| 1212 | """Run pytest inline or in a subprocess, depending on the command line |
no test coverage detected