Skip to content

Commit 3b5d269

Browse files
tests/client: move place creation to new create_place() factory fixture
This allows tests to create multiple places on demand. The places are released and deleted afterwards. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent 2daa13d commit 3b5d269

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

tests/test_client.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,33 @@ def test_startup(coordinator):
99
pass
1010

1111
@pytest.fixture(scope='function')
12-
def place(coordinator):
13-
with pexpect.spawn('python -m labgrid.remote.client -p test create') as spawn:
14-
spawn.expect(pexpect.EOF)
15-
spawn.close()
12+
def place(create_place):
13+
create_place('test')
14+
15+
@pytest.fixture(scope='function')
16+
def create_place(coordinator):
17+
place_names = []
18+
19+
def _create_place(place_name):
20+
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} create') as spawn:
21+
spawn.expect(pexpect.EOF)
1622
assert spawn.exitstatus == 0, spawn.before.strip()
1723

18-
with pexpect.spawn('python -m labgrid.remote.client -p test set-tags board=123board') as spawn:
19-
spawn.expect(pexpect.EOF)
20-
spawn.close()
24+
place_names.append(place_name)
25+
26+
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} set-tags board=123board') as spawn:
27+
spawn.expect(pexpect.EOF)
2128
assert spawn.exitstatus == 0, spawn.before.strip()
2229

23-
yield
30+
yield _create_place
2431

25-
with pexpect.spawn('python -m labgrid.remote.client -p test delete') as spawn:
26-
spawn.expect(pexpect.EOF)
27-
spawn.close()
32+
for place_name in place_names:
33+
# clean up
34+
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} release') as spawn:
35+
spawn.expect(pexpect.EOF)
36+
37+
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} delete') as spawn:
38+
spawn.expect(pexpect.EOF)
2839
assert spawn.exitstatus == 0, spawn.before.strip()
2940

3041
@pytest.fixture(scope='function')

0 commit comments

Comments
 (0)