Skip to content

Commit 54332fb

Browse files
committed
Tests: refactor process killing
1 parent cf28258 commit 54332fb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/tests_asyncio/test_browser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import asyncio
22
import logging
3-
import os
43
import platform
54
import random
65
import re
7-
import signal
86
import subprocess
97
import time
108
import uuid
@@ -148,8 +146,14 @@ def inject_fixtures(self, caplog):
148146
@staticmethod
149147
def kill_chrome():
150148
for proc in psutil.process_iter(["pid", "name"]):
151-
if proc.info["name"].lower() in ("chrome", "chromium"):
152-
os.kill(proc.info["pid"], signal.SIGKILL)
149+
started_time = proc.create_time() # seconds since since January 1, 1970 UTC
150+
# only consider processes started in the last 10 seconds
151+
if not started_time >= time.time() - 10:
152+
continue
153+
name = proc.info["name"].lower()
154+
if "chrome" in name or "chromium" in name:
155+
proc.kill()
156+
print("Killed process:", proc)
153157

154158
@allow_windows
155159
async def test_browser_closed_restart(self):

0 commit comments

Comments
 (0)