Skip to content

Commit 836cfba

Browse files
authored
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.
1 parent 3b00234 commit 836cfba

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

changelog/13621.contrib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

testing/test_capture.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,13 @@ def tmpfile(pytester: Pytester) -> Generator[BinaryIO]:
983983
def lsof_check():
984984
pid = os.getpid()
985985
try:
986-
out = subprocess.check_output(("lsof", "-p", str(pid))).decode()
987-
except (OSError, subprocess.CalledProcessError, UnicodeDecodeError) as exc:
986+
out = subprocess.check_output(("lsof", "-p", str(pid)), timeout=10).decode()
987+
except (
988+
OSError,
989+
UnicodeDecodeError,
990+
subprocess.CalledProcessError,
991+
subprocess.TimeoutExpired,
992+
) as exc:
988993
# about UnicodeDecodeError, see note on pytester
989994
pytest.skip(f"could not run 'lsof' ({exc!r})")
990995
yield

0 commit comments

Comments
 (0)