From f1fc14021d0596e30a8822530d1f56dcea744ce5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 28 Jul 2025 15:16:41 +0200 Subject: [PATCH] selftests: Set a timeout for lsof (#13621) In case of hanging filesystems (e.g. unreachable sshfs), `lsof` can hang for a long time (3 minutes in my case). Set a more reasonable timeout and skip the affected test (like already done with other problems regarding lsof) in such a case. (cherry picked from commit 836cfbac1f49c069191b5859fbc1c1763e5077ea) --- changelog/13621.contrib.rst | 1 + testing/test_capture.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelog/13621.contrib.rst 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