Provide helpful details about failed subcommand runs
(self, cmd_line)
| 62 | ("rc", "out", "err"))): |
| 63 | """Helper for reporting Python subprocess run results""" |
| 64 | def fail(self, cmd_line): |
| 65 | """Provide helpful details about failed subcommand runs""" |
| 66 | # Limit to 300 lines of ASCII characters |
| 67 | maxlen = 300 * 100 |
| 68 | out, err = self.out, self.err |
| 69 | if len(out) > maxlen: |
| 70 | out = b'(... truncated stdout ...)' + out[-maxlen:] |
| 71 | if len(err) > maxlen: |
| 72 | err = b'(... truncated stderr ...)' + err[-maxlen:] |
| 73 | out = out.decode('utf8', 'replace').rstrip() |
| 74 | err = err.decode('utf8', 'replace').rstrip() |
| 75 | |
| 76 | exitcode = self.rc |
| 77 | signame = support.get_signal_name(exitcode) |
| 78 | if signame: |
| 79 | exitcode = f"{exitcode} ({signame})" |
| 80 | raise AssertionError(f"Process return code is {exitcode}\n" |
| 81 | f"command line: {cmd_line!r}\n" |
| 82 | f"\n" |
| 83 | f"stdout:\n" |
| 84 | f"---\n" |
| 85 | f"{out}\n" |
| 86 | f"---\n" |
| 87 | f"\n" |
| 88 | f"stderr:\n" |
| 89 | f"---\n" |
| 90 | f"{err}\n" |
| 91 | f"---") |
| 92 | |
| 93 | |
| 94 | # Executing the interpreter in a subprocess |