Running `pytest | head -1` and similar causes an annoying error to be
printed to stderr:
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
(or possibly even a propagating exception in older/other Python versions).
The standard UNIX behavior is to handle the EPIPE silently. To
recommended method to do this in Python is described here:
https://docs.python.org/3/library/signal.html#note-on-sigpipe
It is not appropriate to apply this recommendation to `pytest.main()`,
which is used programmatically for in-process runs. Hence, change
pytest's entrypoint to a new `pytest.console_main()` function, to be
used exclusively by pytest's CLI, and add the SIGPIPE code there.
Fixes #4375.
4 lines
236 B
ReStructuredText
4 lines
236 B
ReStructuredText
The ``pytest`` command now supresses the ``BrokenPipeError`` error message that
|
|
is printed to stderr when the output of ``pytest`` is piped and and the pipe is
|
|
closed by the piped-to program (common examples are ``less`` and ``head``).
|