diff --git a/changelog/13621.contrib.rst b/changelog/13621.contrib.rst new file mode 100644 index 00000000000..c5e622b7619 --- /dev/null +++ b/changelog/13621.contrib.rst @@ -0,0 +1 @@ +pytest's own testsuite now handles the ``lsof`` command hanging (e.g. due to unreachable network filesystems), with the affected selftests being skipped after 10 seconds. diff --git a/testing/test_capture.py b/testing/test_capture.py index d9dacebd938..0f64e9c73d8 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -983,8 +983,13 @@ def tmpfile(pytester: Pytester) -> Generator[BinaryIO]: def lsof_check(): pid = os.getpid() try: - out = subprocess.check_output(("lsof", "-p", str(pid))).decode() - except (OSError, subprocess.CalledProcessError, UnicodeDecodeError) as exc: + out = subprocess.check_output(("lsof", "-p", str(pid)), timeout=10).decode() + except ( + OSError, + UnicodeDecodeError, + subprocess.CalledProcessError, + subprocess.TimeoutExpired, + ) as exc: # about UnicodeDecodeError, see note on pytester pytest.skip(f"could not run 'lsof' ({exc!r})") yield