Skip to content

Commit 8a06609

Browse files
committed
Add setup and teardown functions so tests pass even when JUPYTER_PREFER_ENV_PATH is defined in the environment
1 parent 7a8e44c commit 8a06609

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

jupyter_core/tests/test_command.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
)
1818

1919

20+
resetenv = patch.dict(os.environ)
21+
22+
def setup_module():
23+
resetenv.start()
24+
os.environ.pop('JUPYTER_PREFER_ENV_PATH', None)
25+
26+
def teardown_module():
27+
resetenv.stop()
28+
2029
def get_jupyter_output(cmd):
2130
"""Get output of a jupyter command"""
2231
if not isinstance(cmd, list):

jupyter_core/tests/test_paths.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@
4848

4949
jupyter_config_env = '/jupyter-cfg'
5050
config_env = patch.dict('os.environ', {'JUPYTER_CONFIG_DIR': jupyter_config_env})
51+
prefer_env = patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'True'})
52+
53+
resetenv = patch.dict(os.environ)
54+
55+
def setup_module():
56+
resetenv.start()
57+
os.environ.pop('JUPYTER_PREFER_ENV_PATH', None)
58+
59+
def teardown_module():
60+
resetenv.stop()
61+
5162

5263

5364
def realpath(path):
5465
return os.path.abspath(os.path.realpath(os.path.expanduser(path)))
5566

5667
home_jupyter = realpath('~/.jupyter')
5768

58-
5969
def test_envset():
6070
true_values = ['', 'True', 'on', 'yes', 'Y', '1', 'anything']
6171
false_values = ['n', 'No', 'N', 'fAlSE', '0', '0.0', 'Off']
@@ -199,7 +209,7 @@ def test_jupyter_path_no_user_site():
199209
assert path[1] == paths.ENV_JUPYTER_PATH[0]
200210

201211
def test_jupyter_path_prefer_env():
202-
with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}):
212+
with prefer_env:
203213
path = jupyter_path()
204214
assert path[0] == paths.ENV_JUPYTER_PATH[0]
205215
assert path[1] == jupyter_data_dir()
@@ -241,7 +251,7 @@ def test_jupyter_config_path_no_user_site():
241251

242252

243253
def test_jupyter_config_path_prefer_env():
244-
with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}):
254+
with prefer_env:
245255
path = jupyter_config_path()
246256
assert path[0] == paths.ENV_CONFIG_PATH[0]
247257
assert path[1] == jupyter_config_dir()

0 commit comments

Comments
 (0)