forked from milvus-io/pymilvus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
133 lines (96 loc) · 3.26 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import time
# Third party imports
import pytest
# local application imports
from factorys import gen_unique_str, fake, records_factory
from milvus import Milvus, IndexType, MetricType
default_host = "127.0.0.1"
default_grpc_port = 19530
default_http_port = 19121
def pytest_addoption(parser):
parser.addoption("--ip", action="store", default=default_host)
parser.addoption("--handler", action="store", default="GRPC")
parser.addoption("--port", action="store", default=default_grpc_port)
@pytest.fixture(scope="module")
def gip(request):
ip_ = request.config.getoption("--ip")
port_ = request.config.getoption("--port")
return ip_, port_
@pytest.fixture(scope="module")
def ghandler(request):
handler_ = request.config.getoption("--handler")
return handler_
@pytest.fixture(scope="module")
def connect(request, ghandler):
ip = request.config.getoption("--ip")
handler = request.config.getoption("--handler")
port_default = default_http_port if handler == "HTTP" else default_grpc_port
port = request.config.getoption("--port", default=port_default)
client = Milvus(host=ip, port=port, handler=ghandler)
# milvus.connect()
def fin():
try:
client.close()
except:
pass
request.addfinalizer(fin)
return client
@pytest.fixture(scope="module")
def gcon(request, ghandler):
ip = request.config.getoption("--ip")
port = request.config.getoption("--port")
client = Milvus(host=ip, port=port, handler=ghandler)
def fin():
try:
client.close()
pass
except Exception as e:
print(e)
pass
request.addfinalizer(fin)
return client
@pytest.fixture(scope="module")
def args(request):
ip = request.config.getoption("--ip")
port = request.config.getoption("--port")
args = {"ip": ip, "port": port}
return args
@pytest.fixture(scope="function")
def table(request, connect):
ori_table_name = getattr(request.module, "table_id", "test")
table_name = gen_unique_str(ori_table_name)
dim = getattr(request.module, "dim", "128")
param = {'collection_name': table_name,
'dimension': dim,
'index_type': IndexType.IVFLAT,
'metric_type': MetricType.L2
}
connect.create_collection(param)
def teardown():
connect.drop_collection(table_name)
request.addfinalizer(teardown)
return table_name
@pytest.fixture(scope="function")
def gcollection(request, gcon):
table_name = fake.collection_name()
dim = getattr(request.module, "dim", 128)
param = {'collection_name': table_name,
'dimension': dim,
'index_file_size': 1024,
'metric_type': MetricType.L2
}
gcon.create_collection(param)
gcon.flush([table_name])
def teardown():
status, table_names = gcon.list_collections()
for name in table_names:
gcon.drop_collection(name)
request.addfinalizer(teardown)
return table_name
@pytest.fixture(scope='function')
def gvector(request, gcon, gcollection):
dim = getattr(request.module, 'dim', 128)
records = records_factory(dim, 10000)
gcon.insert(gcollection, records)
gcon.flush([gcollection])
return gcollection