Capture output from a failed subprocess for easier debugging. The output this handler produces can be a little hard to read, but at least it has all the details.
(self)
| 1032 | |
| 1033 | @contextlib.contextmanager |
| 1034 | def nicer_error(self): |
| 1035 | """ |
| 1036 | Capture output from a failed subprocess for easier debugging. |
| 1037 | |
| 1038 | The output this handler produces can be a little hard to read, |
| 1039 | but at least it has all the details. |
| 1040 | """ |
| 1041 | try: |
| 1042 | yield |
| 1043 | except subprocess.CalledProcessError as exc: |
| 1044 | out = (exc.output or b'').decode(errors="replace") |
| 1045 | err = (exc.stderr or b'').decode(errors="replace") |
| 1046 | self.fail( |
| 1047 | f"{exc}\n\n" |
| 1048 | f"**Subprocess Output**\n{out}\n\n" |
| 1049 | f"**Subprocess Error**\n{err}" |
| 1050 | ) |
| 1051 | |
| 1052 | @requires_venv_with_pip() |
| 1053 | @requires_resource('cpu') |
no test coverage detected