Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions dask_kubernetes/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import contextlib
import pathlib
import os
import subprocess
Expand All @@ -17,6 +18,30 @@
check_dependency("docker")


@contextlib.contextmanager
def set_env(**environ):
"""
Temporarily set the process environment variables.

>>> with set_env(PLUGINS_DIR=u'test/plugins'):
... "PLUGINS_DIR" in os.environ
True

>>> "PLUGINS_DIR" in os.environ
False

:type environ: dict[str, unicode]
:param environ: Environment variables to set
"""
old_environ = dict(os.environ)
os.environ.update(environ)
try:
yield
finally:
os.environ.clear()
os.environ.update(old_environ)


@pytest.fixture()
def kopf_runner(k8s_cluster):
yield KopfRunner(["run", "-m", "dask_kubernetes.operator", "--verbose"])
Expand All @@ -40,10 +65,9 @@ def k8s_cluster(request, docker_image):
image=image,
)
kind_cluster.create()
os.environ["KUBECONFIG"] = str(kind_cluster.kubeconfig_path)
kind_cluster.load_docker_image(docker_image)
yield kind_cluster
del os.environ["KUBECONFIG"]
with set_env(KUBECONFIG=str(kind_cluster.kubeconfig_path)):
yield kind_cluster
if not request.config.getoption("keep_cluster"):
kind_cluster.delete()

Expand Down
Loading