Skip to content

Commit

Permalink
check open processes in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlashner committed Dec 18, 2024
1 parent e355b34 commit 7aa2fcc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import psutil
import os
import pytest

@pytest.fixture(autouse=True)
def check_subprocesses():
# Get a list of child PIDs before the test starts
parent = psutil.Process(os.getpid())
before_children = {child.pid for child in parent.children(recursive=True)}

yield

after_children = {child.pid for child in parent.children(recursive=True)}
leftover_processes = after_children - before_children

if leftover_processes:
leftover_details = [
f"PID {p.pid}: {p.cmdline()}" for p in parent.children(recursive=True) if p.pid in leftover_processes
]
pytest.fail(f"Lingering subprocesses detected:\n" + "\n".join(leftover_details))

0 comments on commit 7aa2fcc

Please sign in to comment.