Skip to content

Commit 15da271

Browse files
tests/conftest: make coordinator fixture use a helper class Coordinator
The same was previously implemented for the exporter. Since we need the same functionality also for the coordinator (along with suspend_tree()/resume_tree() functionality to be moved in a future commit), let's refactor it now. Signed-off-by: Bastian Krause <[email protected]>
1 parent 373874b commit 15da271

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

tests/conftest.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ def start(self):
127127
self.start_reader()
128128

129129

130+
class Coordinator(LabgridComponent):
131+
def start(self):
132+
assert self.spawn is None
133+
assert self.reader is None
134+
135+
self.spawn = pexpect.spawn(
136+
'labgrid-coordinator',
137+
logfile=Prefixer(sys.stdout.buffer, 'coordinator'),
138+
cwd=self.cwd)
139+
try:
140+
self.spawn.expect('Coordinator ready')
141+
except Exception as e:
142+
raise Exception(f"coordinator startup failed with {self.spawn.before}") from e
143+
144+
self.start_reader()
145+
146+
130147
@pytest.fixture(scope='function')
131148
def target():
132149
return Target('Test')
@@ -166,28 +183,12 @@ def serial_driver_no_name(target, serial_port, mocker):
166183

167184
@pytest.fixture(scope='function')
168185
def coordinator(tmpdir):
186+
coordinator = Coordinator(tmpdir)
187+
coordinator.start()
169188

170-
spawn = pexpect.spawn(
171-
'labgrid-coordinator',
172-
logfile=Prefixer(sys.stdout.buffer, 'coordinator'),
173-
cwd=str(tmpdir))
174-
try:
175-
spawn.expect('Coordinator ready')
176-
except:
177-
print(f"coordinator startup failed with {spawn.before}")
178-
raise
179-
reader = threading.Thread(target=keep_reading, name='coordinator-reader', args=(spawn,), daemon=True)
180-
reader.start()
181-
yield spawn
182-
183-
# let coverage write its data:
184-
# https://coverage.readthedocs.io/en/latest/subprocess.html#process-termination
185-
print("stopping coordinator")
186-
spawn.kill(SIGTERM)
187-
spawn.expect(pexpect.EOF)
188-
spawn.wait()
189-
190-
reader.join()
189+
yield coordinator
190+
191+
coordinator.stop()
191192

192193
@pytest.fixture(scope='function')
193194
def exporter(tmpdir, coordinator):

0 commit comments

Comments
 (0)