Skip to content

Commit b83cc58

Browse files
authored
fix(tests): Use a more targeted lsof invocation (#419)
Using `lsof | grep $PID` is prone to false hits. Use `lsof -p $PID` instead.
1 parent ff5278f commit b83cc58

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ ignore = [
182182
"FBT001", # boolean-typed positional argument in function definition
183183
"PLR2004", # magic value used in comparison
184184
"S101", # use of `assert` detected
185-
"S602", # `subprocess` call with `shell=True`
186-
"S603", # `subprocess` call
185+
#"S602", # `subprocess` call with `shell=True`
186+
"S603", # `subprocess` call: check for execution of untrusted input
187+
"S607", # `subprocess` call without explicit paths
187188
"SLF001", # private member accessed
188189
]

src/tests/test_leaks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def get_opened_socket() -> int:
2020
"""GNU/Linux: a way to get the opened sockets count.
2121
It will be used to check X server connections are well closed.
2222
"""
23-
cmd = f"lsof -U | grep {PID}"
24-
output = subprocess.check_output(cmd, shell=True)
25-
return len(output.splitlines())
23+
output = subprocess.check_output(["lsof", "-a", "-U", "-Ff", f"-p{PID}"])
24+
# The first line will be "p{PID}". The remaining lines start with "f", one per open socket.
25+
return len([line for line in output.splitlines() if line.startswith(b"f")])
2626

2727

2828
def get_handles() -> int:

0 commit comments

Comments
 (0)