2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-23 18:47:11 +00:00

38 lines
952 B
Python
Raw Normal View History

import logging
from pathlib import Path
from typing import MutableMapping
2018-07-27 10:18:29 -04:00
import pytest
from shared_zone_test_context import SharedZoneTestContext
STATE_FILE = Path("testing_state.json")
logger = logging.getLogger(__name__)
ctx_cache: MutableMapping[str, SharedZoneTestContext] = {}
2018-07-27 10:18:29 -04:00
@pytest.fixture(scope="session")
def shared_zone_test_context(tmp_path_factory, worker_id):
if worker_id == "master":
partition_id = "1"
else:
partition_id = str(int(worker_id.replace("gw", "")) + 1)
if ctx_cache.get(partition_id) is not None:
return ctx_cache[partition_id]
ctx = ctx_cache[partition_id] = SharedZoneTestContext(partition_id)
ctx.setup()
yield ctx
del ctx_cache[partition_id]
ctx.tear_down()
@pytest.hookimpl(tryfirst=True)
def pytest_keyboard_interrupt():
print("cleaning up state due to interrupt")
for partition_id, context in ctx_cache.items():
context.tear_down()