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