Skip to content

Commit 5b2776d

Browse files
tests/conftest: move suspend_tree/resume_tree into LabgridComponent
Previously only tests/test_client.py could use the suspend_tree() and resume_tree() functionality. Since this is also useful for exporter + coordinator tests, move it into the generic LabgridComponent class. Signed-off-by: Bastian Krause <[email protected]>
1 parent 15da271 commit 5b2776d

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from labgrid.resource import RawSerialPort, NetworkSerialPort
1212
from labgrid.driver.fake import FakeConsoleDriver
1313

14+
psutil = pytest.importorskip("psutil")
15+
1416
@pytest.fixture(scope="session")
1517
def curses_init():
1618
""" curses only reads the terminfo DB once on the first import, so make
@@ -104,6 +106,18 @@ def exitstatus(self):
104106
def pid(self):
105107
return self.spawn.pid
106108

109+
def suspend_tree(self):
110+
main = psutil.Process(self.pid)
111+
main.suspend()
112+
for child in main.children(recursive=True):
113+
child.suspend()
114+
115+
def resume_tree(self):
116+
main = psutil.Process(self.pid)
117+
main.resume()
118+
for child in main.children(recursive=True):
119+
child.resume()
120+
107121

108122
class Exporter(LabgridComponent):
109123
def __init__(self, config, cwd):

tests/test_client.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55
import pytest
66
import pexpect
77

8-
psutil = pytest.importorskip("psutil")
9-
10-
def suspend_tree(pid):
11-
main = psutil.Process(pid)
12-
main.suspend()
13-
for child in main.children(recursive=True):
14-
child.suspend()
15-
16-
def resume_tree(pid):
17-
main = psutil.Process(pid)
18-
main.resume()
19-
for child in main.children(recursive=True):
20-
child.resume()
21-
228
def test_startup(coordinator):
239
pass
2410

@@ -68,15 +54,15 @@ def test_connect_error():
6854
assert spawn.exitstatus == 1, spawn.before.strip()
6955

7056
def test_connect_timeout(coordinator):
71-
suspend_tree(coordinator.pid)
57+
coordinator.suspend_tree()
7258
try:
7359
with pexpect.spawn('python -m labgrid.remote.client places') as spawn:
7460
spawn.expect("connection attempt timed out before receiving SETTINGS frame")
7561
spawn.expect(pexpect.EOF)
7662
spawn.close()
7763
assert spawn.exitstatus == 1, spawn.before.strip()
7864
finally:
79-
resume_tree(coordinator.pid)
65+
coordinator.resume_tree()
8066
pass
8167

8268
def test_place_show(place):
@@ -488,7 +474,7 @@ def test_exporter_timeout(place, exporter):
488474
spawn.close()
489475
assert spawn.exitstatus == 0, spawn.before.strip()
490476

491-
suspend_tree(exporter.pid)
477+
exporter.suspend_tree()
492478
try:
493479
time.sleep(30)
494480

@@ -499,7 +485,7 @@ def test_exporter_timeout(place, exporter):
499485
assert spawn.exitstatus == 0, spawn.before.strip()
500486
assert b'/Testport/NetworkSerialPort' not in spawn.before
501487
finally:
502-
resume_tree(exporter.pid)
488+
exporter.resume_tree()
503489

504490
# the exporter should quit by itself now
505491
time.sleep(5)

tests/test_coordinator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import labgrid.remote.generated.labgrid_coordinator_pb2_grpc as labgrid_coordinator_pb2_grpc
55
import labgrid.remote.generated.labgrid_coordinator_pb2 as labgrid_coordinator_pb2
66

7-
psutil = pytest.importorskip("psutil")
8-
97
@pytest.fixture(scope='function')
108
def channel_stub():
119
import queue

0 commit comments

Comments
 (0)