diff --git a/jupyter_server/pytest_plugin.py b/jupyter_server/pytest_plugin.py index 05c2000c2f..00aea6bd71 100644 --- a/jupyter_server/pytest_plugin.py +++ b/jupyter_server/pytest_plugin.py @@ -1,6 +1,7 @@ import os import sys import json +import shutil import pytest import asyncio from binascii import hexlify @@ -71,7 +72,6 @@ def mkdir(tmp_path, *parts): } argv = pytest.fixture(lambda: []) - @pytest.fixture def environ( monkeypatch, @@ -88,6 +88,18 @@ def environ( ): monkeypatch.setenv("HOME", str(home_dir)) monkeypatch.setenv("PYTHONPATH", os.pathsep.join(sys.path)) + + # Get path to nbconvert template directory *before* + # monkeypatching the paths env variable. + possible_paths = jupyter_core.paths.jupyter_path('nbconvert', 'templates') + nbconvert_path = None + for path in possible_paths: + if os.path.exists(path): + nbconvert_path = path + break + + nbconvert_target = data_dir / 'nbconvert' / 'templates' + # monkeypatch.setenv("JUPYTER_NO_CONFIG", "1") monkeypatch.setenv("JUPYTER_CONFIG_DIR", str(config_dir)) monkeypatch.setenv("JUPYTER_DATA_DIR", str(data_dir)) @@ -101,6 +113,10 @@ def environ( ) monkeypatch.setattr(jupyter_core.paths, "ENV_CONFIG_PATH", [str(env_config_path)]) + # copy nbconvert templates to new tmp data_dir. + if nbconvert_path: + shutil.copytree(nbconvert_path, str(nbconvert_target)) + @pytest.fixture def extension_environ(env_config_path, monkeypatch):