2018-08-28 12:09:05 +02:00
|
|
|
"""pytest fixtures"""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from pytest import fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@fixture
|
|
|
|
|
def preserve_config(request):
|
|
|
|
|
"""Fixture to save and restore config around tests"""
|
2018-10-31 10:25:29 -07:00
|
|
|
# Import TLJH only when needed. This lets us run tests in places
|
|
|
|
|
# where TLJH is not installed - particularly, the 'distro check' test.
|
|
|
|
|
from tljh.config import CONFIG_FILE, reload_component
|
2021-11-01 09:42:45 +01:00
|
|
|
|
2018-08-28 12:09:05 +02:00
|
|
|
if os.path.exists(CONFIG_FILE):
|
|
|
|
|
with open(CONFIG_FILE) as f:
|
|
|
|
|
save_config = f.read()
|
|
|
|
|
else:
|
|
|
|
|
save_config = None
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
if save_config:
|
|
|
|
|
with open(CONFIG_FILE, "w") as f:
|
|
|
|
|
f.write(save_config)
|
|
|
|
|
elif os.path.exists(CONFIG_FILE):
|
|
|
|
|
os.remove(CONFIG_FILE)
|
|
|
|
|
reload_component("hub")
|
|
|
|
|
reload_component("proxy")
|