-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
41 lines (28 loc) · 1007 Bytes
/
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
from pathlib import Path
import pytest
from motor.motor_asyncio import AsyncIOMotorClient
def pytest_addoption(parser):
parser.addoption(
"--mongo-connection-string",
action="store",
default="mongodb://localhost:27017",
)
@pytest.fixture
def revisions_path() -> Path:
return Path(__file__).parent / "tests/revisions"
@pytest.fixture
def mongo_name(worker_id: str) -> str:
return "vt-test-{}".format(worker_id)
@pytest.fixture
def mongo_connection_string(request, mongo_name) -> str:
return request.config.getoption("mongo_connection_string")
@pytest.fixture
def full_mongo_connection_string(mongo_connection_string, mongo_name):
return f"{mongo_connection_string}/{mongo_name}"
@pytest.fixture
async def mongo(mongo_connection_string, mongo_name):
client = AsyncIOMotorClient(mongo_connection_string)
await client.drop_database(mongo_name)
mongo = client.get_database(mongo_name)
yield mongo
await client.drop_database(mongo)