Skip to content

Commit df63f6c

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

10 files changed

Lines changed: 45 additions & 310 deletions

test/conftest.py

Lines changed: 37 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,51 @@ 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(
169+
"TcsParams",
170+
[
171+
"path_to_cfg_dir",
172+
"connection_test",
173+
"connection_test_user",
174+
"connection_test_password",
175+
"instance_name",
176+
"instance_port",
177+
"instance_host",
178+
],
179+
)
180+
181+
182+
@pytest.fixture(scope="function")
183+
def tcs_params(request) -> TcsParams:
184+
return TcsParams(
185+
path_to_cfg_dir=request.path.parent / "test_tcs_app",
186+
connection_test=True,
187+
connection_test_user="client",
188+
connection_test_password="secret",
189+
instance_name="instance-001",
190+
instance_host="localhost",
191+
instance_port="3303",
192+
)
170193

171194

172195
@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")
196+
def tcs(request, tmp_path, tcs_params):
197+
if utils.is_tarantool_less_3() or not utils.is_tarantool_ee():
198+
pytest.skip()
199+
test_app_path = tcs_params.path_to_cfg_dir / "config.yaml"
175200
inst = utils.TarantoolTestInstance(
176201
test_app_path,
177-
fixture_params.get("path_to_cfg_dir"),
202+
tcs_params.path_to_cfg_dir,
178203
"",
179204
tmp_path,
180205
)
181206
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"),
207+
connection_test=tcs_params.connection_test,
208+
connection_test_user=tcs_params.connection_test_user,
209+
connection_test_password=tcs_params.connection_test_password,
210+
instance_name=tcs_params.instance_name,
211+
instance_host=tcs_params.instance_host,
212+
instance_port=tcs_params.instance_port,
188213
)
189214
request.addfinalizer(lambda: inst.stop())
190215
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 & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import pytest
2-
from tarantool.connection import os
32

43
from utils import (
5-
get_fixture_tcs_params,
6-
is_tarantool_ee,
7-
is_tarantool_less_3,
84
run_command_and_get_output,
95
)
106

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

168
def to_etcd_key(key):
179
return f"/prefix/config/{key}"
@@ -41,12 +33,7 @@ def to_etcd_key(key):
4133

4234

4335
@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
36+
def test_cluster_demote_single_key(tt_cmd, tmpdir_with_cfg, instance_name, request):
5037
instance = request.getfixturevalue(instance_name)
5138
tmpdir = tmpdir_with_cfg
5239
conn = instance.conn()
@@ -104,13 +91,7 @@ def test_cluster_demote_many_keys(
10491
key,
10592
instance_name,
10693
request,
107-
fixture_params,
10894
):
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
11495
instance = request.getfixturevalue(instance_name)
11596
tmpdir = tmpdir_with_cfg
11697
conn = instance.conn()
@@ -186,15 +167,9 @@ def test_cluster_demote_no_auth(
186167
tt_cmd,
187168
tmpdir_with_cfg,
188169
instance_name,
189-
fixture_params,
190170
request,
191171
err_msg,
192172
):
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
198173
instance = request.getfixturevalue(instance_name)
199174
tmpdir = tmpdir_with_cfg
200175

@@ -231,14 +206,8 @@ def test_cluster_demote_bad_auth(
231206
tmpdir_with_cfg,
232207
instance_name,
233208
err_msg,
234-
fixture_params,
235209
request,
236210
):
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
242211
instance = request.getfixturevalue(instance_name)
243212
tmpdir = tmpdir_with_cfg
244213

@@ -268,12 +237,7 @@ def test_cluster_demote_bad_auth(
268237
("tcs", "env"),
269238
],
270239
)
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
240+
def test_cluster_demote_auth(tt_cmd, tmpdir_with_cfg, instance_name, auth, request):
277241
instance = request.getfixturevalue(instance_name)
278242
tmpdir = tmpdir_with_cfg
279243
conn = instance.conn()

test/integration/cluster/test_cluster_expel.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import pytest
2-
from tarantool.connection import os
32

43
from utils import (
5-
get_fixture_tcs_params,
6-
is_tarantool_ee,
7-
is_tarantool_less_3,
84
run_command_and_get_output,
95
)
106

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

168
def to_etcd_key(key):
179
return f"/prefix/config/{key}"
@@ -38,12 +30,7 @@ def test_cluster_expel_missing_instance_arg(tt_cmd, tmpdir_with_cfg):
3830

3931

4032
@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
33+
def test_cluster_expel_no_instance(tt_cmd, tmpdir_with_cfg, instance_name, request):
4734
instance = request.getfixturevalue(instance_name)
4835

4936
conn = instance.conn()
@@ -68,12 +55,7 @@ def test_cluster_expel_no_instance(tt_cmd, tmpdir_with_cfg, instance_name, fixtu
6855

6956

7057
@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
58+
def test_cluster_expel_single_key(tt_cmd, tmpdir_with_cfg, instance_name, request):
7759
instance = request.getfixturevalue(instance_name)
7860
conn = instance.conn()
7961
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)