mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
move tljh_dir fixture to conftest
so it can be used everywhere
This commit is contained in:
24
tests/conftest.py
Normal file
24
tests/conftest.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
"""pytest fixtures"""
|
||||||
|
from importlib import reload
|
||||||
|
import os
|
||||||
|
import types
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import tljh
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tljh_dir(tmpdir):
|
||||||
|
"""Fixture for setting up a temporary tljh dir"""
|
||||||
|
tljh_dir = str(tmpdir.join("tljh").mkdir())
|
||||||
|
with mock.patch.dict(os.environ, {"TLJH_INSTALL_PREFIX": tljh_dir}):
|
||||||
|
reload(tljh)
|
||||||
|
for name in dir(tljh):
|
||||||
|
mod = getattr(tljh, name)
|
||||||
|
if isinstance(mod, types.ModuleType) and mod.__name__.startswith('tljh.'):
|
||||||
|
reload(mod)
|
||||||
|
assert tljh.config.INSTALL_PREFIX == tljh_dir
|
||||||
|
os.makedirs(tljh.config.STATE_DIR)
|
||||||
|
yield tljh_dir
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
Test configuration commandline tools
|
Test configuration commandline tools
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from importlib import reload
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@@ -12,21 +11,6 @@ import pytest
|
|||||||
from tljh import config, configurer
|
from tljh import config, configurer
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tljh_dir(tmpdir):
|
|
||||||
"""Fixture for setting up a temporary tljh dir"""
|
|
||||||
tljh_dir = str(tmpdir.join("tljh").mkdir())
|
|
||||||
with mock.patch.dict(
|
|
||||||
os.environ,
|
|
||||||
{"TLJH_INSTALL_PREFIX": tljh_dir}
|
|
||||||
):
|
|
||||||
reload(config)
|
|
||||||
reload(configurer)
|
|
||||||
assert config.INSTALL_PREFIX == tljh_dir
|
|
||||||
os.makedirs(config.STATE_DIR)
|
|
||||||
yield tljh_dir
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_no_mutate():
|
def test_set_no_mutate():
|
||||||
conf = {}
|
conf = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user