Skip to content

Commit 62bd12a

Browse files
committed
test: simplify using of tcs fixture
Part of #1193
1 parent a7e8f30 commit 62bd12a

10 files changed

Lines changed: 42 additions & 306 deletions

test/conftest.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shutil
44
import signal
55
import subprocess
6+
from collections import namedtuple
67
from pathlib import Path
78

89
import etcd_helper
@@ -164,27 +165,48 @@ def cartridge_app(request, cartridge_app_session):
164165
return cartridge_app_session
165166

166167

167-
@pytest.fixture
168-
def fixture_params():
169-
return {}
168+
TcsParams = namedtuple("TcsParams", [
169+
"path_to_cfg_dir",
170+
"connection_test",
171+
"connection_test_user",
172+
"connection_test_password",
173+
"instance_name",
174+
"instance_port",
175+
"instance_host",
176+
])
177+
178+
179+
@pytest.fixture(scope="function")
180+
def tcs_params(request) -> TcsParams:
181+
return TcsParams(
182+
path_to_cfg_dir=request.path.parent / "test_tcs_app",
183+
connection_test=True,
184+
connection_test_user="client",
185+
connection_test_password="secret",
186+
instance_name="instance-001",
187+
instance_host="localhost",
188+
instance_port="3303",
189+
)
170190

171191

172192
@pytest.fixture(scope="function")
173-
def tcs(request, tmp_path, fixture_params):
174-
test_app_path = os.path.join(fixture_params.get("path_to_cfg_dir"), "config.yaml")
193+
def tcs(request, tmp_path, tcs_params):
194+
if utils.is_tarantool_less_3() or not utils.is_tarantool_ee():
195+
pytest.skip()
196+
test_app_path = tcs_params.path_to_cfg_dir / "config.yaml"
175197
inst = utils.TarantoolTestInstance(
176198
test_app_path,
177-
fixture_params.get("path_to_cfg_dir"),
199+
tcs_params.path_to_cfg_dir,
178200
"",
179201
tmp_path,
180202
)
181203
inst.start(
182-
connection_test=fixture_params.get("connection_test"),
183-
connection_test_user=fixture_params.get("connection_test_user"),
184-
connection_test_password=fixture_params.get("connection_test_password"),
185-
instance_name=fixture_params.get("instance_name"),
186-
instance_host=fixture_params.get("instance_host"),
187-
instance_port=fixture_params.get("instance_port"),
204+
connection_test=tcs_params.connection_test,
205+
connection_test_user=tcs_params.connection_test_user,
206+
connection_test_password=tcs_params.connection_test_password,
207+
instance_name=tcs_params.instance_name,
208+
instance_host=tcs_params.instance_host,
209+
instance_port=tcs_params.instance_port,
188210
)
189211
request.addfinalizer(lambda: inst.stop())
190212
return inst

test/integration/aeon/test_aeon.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
import pytest
77

8-
from utils import get_fixture_tcs_params, is_tarantool_ee, is_tarantool_less_3
9-
10-
fixture_tcs_params = get_fixture_tcs_params(
11-
os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_tcs_app"),
12-
)
13-
148
AeonConnectCommand = ("aeon", "connect")
159

1610

@@ -385,11 +379,7 @@ def test_cli_plain_app_success(tt_cmd, app_name, tmpdir_with_cfg, aeon_plain_fil
385379
assert tt.returncode == 0
386380

387381

388-
def test_cli_plain_tcs_success(tt_cmd, tmpdir_with_cfg, request, fixture_params, aeon_plain_file):
389-
if is_tarantool_less_3() or not is_tarantool_ee():
390-
pytest.skip()
391-
for k, v in fixture_tcs_params.items():
392-
fixture_params[k] = v
382+
def test_cli_plain_tcs_success(tt_cmd, tmpdir_with_cfg, request, aeon_plain_file):
393383
instance = request.getfixturevalue("tcs")
394384
tmpdir = tmpdir_with_cfg
395385

test/integration/cluster/test_cluster_demote.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22
from tarantool.connection import os
33

44
from utils import (
5-
get_fixture_tcs_params,
6-
is_tarantool_ee,
7-
is_tarantool_less_3,
85
run_command_and_get_output,
96
)
107

11-
fixture_tcs_params = get_fixture_tcs_params(
12-
os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_tcs_app"),
13-
)
14-
158

169
def to_etcd_key(key):
1710
return f"/prefix/config/{key}"
@@ -41,12 +34,7 @@ def to_etcd_key(key):
4134

4235

4336
@pytest.mark.parametrize("instance_name", ["etcd", "tcs"])
44-
def test_cluster_demote_single_key(tt_cmd, tmpdir_with_cfg, instance_name, request, fixture_params):
45-
if instance_name == "tcs":
46-
if is_tarantool_less_3() or not is_tarantool_ee():
47-
pytest.skip()
48-
for k, v in fixture_tcs_params.items():
49-
fixture_params[k] = v
37+
def test_cluster_demote_single_key(tt_cmd, tmpdir_with_cfg, instance_name, request):
5038
instance = request.getfixturevalue(instance_name)
5139
tmpdir = tmpdir_with_cfg
5240
conn = instance.conn()
@@ -104,13 +92,7 @@ def test_cluster_demote_many_keys(
10492
key,
10593
instance_name,
10694
request,
107-
fixture_params,
10895
):
109-
if instance_name == "tcs":
110-
if is_tarantool_less_3() or not is_tarantool_ee():
111-
pytest.skip()
112-
for k, v in fixture_tcs_params.items():
113-
fixture_params[k] = v
11496
instance = request.getfixturevalue(instance_name)
11597
tmpdir = tmpdir_with_cfg
11698
conn = instance.conn()
@@ -186,15 +168,9 @@ def test_cluster_demote_no_auth(
186168
tt_cmd,
187169
tmpdir_with_cfg,
188170
instance_name,
189-
fixture_params,
190171
request,
191172
err_msg,
192173
):
193-
if instance_name == "tcs":
194-
if is_tarantool_less_3() or not is_tarantool_ee():
195-
pytest.skip()
196-
for k, v in fixture_tcs_params.items():
197-
fixture_params[k] = v
198174
instance = request.getfixturevalue(instance_name)
199175
tmpdir = tmpdir_with_cfg
200176

@@ -231,14 +207,8 @@ def test_cluster_demote_bad_auth(
231207
tmpdir_with_cfg,
232208
instance_name,
233209
err_msg,
234-
fixture_params,
235210
request,
236211
):
237-
if instance_name == "tcs":
238-
if is_tarantool_less_3() or not is_tarantool_ee():
239-
pytest.skip()
240-
for k, v in fixture_tcs_params.items():
241-
fixture_params[k] = v
242212
instance = request.getfixturevalue(instance_name)
243213
tmpdir = tmpdir_with_cfg
244214

@@ -268,12 +238,7 @@ def test_cluster_demote_bad_auth(
268238
("tcs", "env"),
269239
],
270240
)
271-
def test_cluster_demote_auth(tt_cmd, tmpdir_with_cfg, instance_name, auth, fixture_params, request):
272-
if instance_name == "tcs":
273-
if is_tarantool_less_3() or not is_tarantool_ee():
274-
pytest.skip()
275-
for k, v in fixture_tcs_params.items():
276-
fixture_params[k] = v
241+
def test_cluster_demote_auth(tt_cmd, tmpdir_with_cfg, instance_name, auth, request):
277242
instance = request.getfixturevalue(instance_name)
278243
tmpdir = tmpdir_with_cfg
279244
conn = instance.conn()

test/integration/cluster/test_cluster_expel.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22
from tarantool.connection import os
33

44
from utils import (
5-
get_fixture_tcs_params,
6-
is_tarantool_ee,
7-
is_tarantool_less_3,
85
run_command_and_get_output,
96
)
107

11-
fixture_tcs_params = get_fixture_tcs_params(
12-
os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_tcs_app"),
13-
)
14-
158

169
def to_etcd_key(key):
1710
return f"/prefix/config/{key}"
@@ -38,12 +31,7 @@ def test_cluster_expel_missing_instance_arg(tt_cmd, tmpdir_with_cfg):
3831

3932

4033
@pytest.mark.parametrize("instance_name", ["etcd", "tcs"])
41-
def test_cluster_expel_no_instance(tt_cmd, tmpdir_with_cfg, instance_name, fixture_params, request):
42-
if instance_name == "tcs":
43-
if is_tarantool_less_3() or not is_tarantool_ee():
44-
pytest.skip()
45-
for k, v in fixture_tcs_params.items():
46-
fixture_params[k] = v
34+
def test_cluster_expel_no_instance(tt_cmd, tmpdir_with_cfg, instance_name, request):
4735
instance = request.getfixturevalue(instance_name)
4836

4937
conn = instance.conn()
@@ -68,12 +56,7 @@ def test_cluster_expel_no_instance(tt_cmd, tmpdir_with_cfg, instance_name, fixtu
6856

6957

7058
@pytest.mark.parametrize("instance_name", ["etcd", "tcs"])
71-
def test_cluster_expel_single_key(tt_cmd, tmpdir_with_cfg, instance_name, fixture_params, request):
72-
if instance_name == "tcs":
73-
if is_tarantool_less_3() or not is_tarantool_ee():
74-
pytest.skip()
75-
for k, v in fixture_tcs_params.items():
76-
fixture_params[k] = v
59+
def test_cluster_expel_single_key(tt_cmd, tmpdir_with_cfg, instance_name, request):
7760
instance = request.getfixturevalue(instance_name)
7861
conn = instance.conn()
7962
tmpdir = tmpdir_with_cfg

test/integration/cluster/test_cluster_promote.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33
import pytest
44

55
from utils import (
6-
get_fixture_tcs_params,
7-
is_tarantool_ee,
8-
is_tarantool_less_3,
96
read_kv,
107
run_command_and_get_output,
118
)
129

13-
fixture_tcs_params = get_fixture_tcs_params(
14-
os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_tcs_app"),
15-
)
16-
1710

1811
def to_etcd_key(key):
1912
return f"/prefix/config/{key}"
@@ -140,14 +133,8 @@ def test_cluster_promote_single_key(
140133
data_dir,
141134
err_text,
142135
instance_name,
143-
fixture_params,
144136
request,
145137
):
146-
if instance_name == "tcs":
147-
if is_tarantool_less_3() or not is_tarantool_ee():
148-
pytest.skip()
149-
for k, v in fixture_tcs_params.items():
150-
fixture_params[k] = v
151138
instance = request.getfixturevalue(instance_name)
152139
test_data_dir = os.path.join(
153140
os.path.dirname(__file__),
@@ -263,14 +250,8 @@ def test_cluster_promote_many_keys(
263250
exp_key,
264251
err_text,
265252
instance_name,
266-
fixture_params,
267253
request,
268254
):
269-
if instance_name == "tcs":
270-
if is_tarantool_less_3() or not is_tarantool_ee():
271-
pytest.skip()
272-
for k, v in fixture_tcs_params.items():
273-
fixture_params[k] = v
274255
instance = request.getfixturevalue(instance_name)
275256
conn = instance.conn()
276257
tmpdir = tmpdir_with_cfg
@@ -332,14 +313,8 @@ def test_cluster_promote_key_specified(
332313
tt_cmd,
333314
tmpdir_with_cfg,
334315
instance_name,
335-
fixture_params,
336316
request,
337317
):
338-
if instance_name == "tcs":
339-
if is_tarantool_less_3() or not is_tarantool_ee():
340-
pytest.skip()
341-
for k, v in fixture_tcs_params.items():
342-
fixture_params[k] = v
343318
instance = request.getfixturevalue(instance_name)
344319
conn = instance.conn()
345320
tmpdir = tmpdir_with_cfg
@@ -414,14 +389,8 @@ def test_cluster_promote_no_auth(
414389
tmpdir_with_cfg,
415390
instance_name,
416391
err_msg,
417-
fixture_params,
418392
request,
419393
):
420-
if instance_name == "tcs":
421-
if is_tarantool_less_3() or not is_tarantool_ee():
422-
pytest.skip()
423-
for k, v in fixture_tcs_params.items():
424-
fixture_params[k] = v
425394
instance = request.getfixturevalue(instance_name)
426395
tmpdir = tmpdir_with_cfg
427396

@@ -458,14 +427,8 @@ def test_cluster_promote_bad_auth(
458427
tmpdir_with_cfg,
459428
instance_name,
460429
err_msg,
461-
fixture_params,
462430
request,
463431
):
464-
if instance_name == "tcs":
465-
if is_tarantool_less_3() or not is_tarantool_ee():
466-
pytest.skip()
467-
for k, v in fixture_tcs_params.items():
468-
fixture_params[k] = v
469432
instance = request.getfixturevalue(instance_name)
470433
tmpdir = tmpdir_with_cfg
471434

@@ -521,14 +484,8 @@ def test_cluster_promote_auth(
521484
tmpdir_with_cfg,
522485
instance_name,
523486
auth,
524-
fixture_params,
525487
request,
526488
):
527-
if instance_name == "tcs":
528-
if is_tarantool_less_3() or not is_tarantool_ee():
529-
pytest.skip()
530-
for k, v in fixture_tcs_params.items():
531-
fixture_params[k] = v
532489
instance = request.getfixturevalue(instance_name)
533490
tmpdir = tmpdir_with_cfg
534491
conn = instance.conn()

0 commit comments

Comments
 (0)