11import os
22import sys
33import json
4+ import shutil
45import pytest
56import asyncio
67from binascii import hexlify
@@ -71,7 +72,6 @@ def mkdir(tmp_path, *parts):
7172}
7273argv = pytest .fixture (lambda : [])
7374
74-
7575@pytest .fixture
7676def environ (
7777 monkeypatch ,
@@ -88,6 +88,18 @@ def environ(
8888):
8989 monkeypatch .setenv ("HOME" , str (home_dir ))
9090 monkeypatch .setenv ("PYTHONPATH" , os .pathsep .join (sys .path ))
91+
92+ # Get path to nbconvert template directory *before*
93+ # monkeypatching the paths env variable.
94+ possible_paths = jupyter_core .paths .jupyter_path ('nbconvert' , 'templates' )
95+ nbconvert_path = None
96+ for path in possible_paths :
97+ if os .path .exists (path ):
98+ nbconvert_path = path
99+ break
100+
101+ nbconvert_target = data_dir / 'nbconvert' / 'templates'
102+
91103 # monkeypatch.setenv("JUPYTER_NO_CONFIG", "1")
92104 monkeypatch .setenv ("JUPYTER_CONFIG_DIR" , str (config_dir ))
93105 monkeypatch .setenv ("JUPYTER_DATA_DIR" , str (data_dir ))
@@ -101,6 +113,10 @@ def environ(
101113 )
102114 monkeypatch .setattr (jupyter_core .paths , "ENV_CONFIG_PATH" , [str (env_config_path )])
103115
116+ # copy nbconvert templates to new tmp data_dir.
117+ if nbconvert_path :
118+ shutil .copytree (nbconvert_path , str (nbconvert_target ))
119+
104120
105121@pytest .fixture
106122def extension_environ (env_config_path , monkeypatch ):
0 commit comments