Skip to content

Commit 10fc02c

Browse files
committed
Clear the test environment before each function run
See jupyter#231
1 parent 6b4df54 commit 10fc02c

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

Diff for: jupyter_core/tests/test_paths.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@
5050
{},
5151
)
5252

53-
no_config_env = patch.dict(
54-
"os.environ",
55-
{
56-
"JUPYTER_PLATFORM_DIRS": "",
57-
"JUPYTER_CONFIG_DIR": "",
58-
"JUPYTER_DATA_DIR": "",
59-
"JUPYTER_RUNTIME_DIR": "",
60-
"JUPYTER_PATH": "",
61-
},
62-
)
53+
environment = patch.dict("os.environ")
6354

6455
use_platformdirs = patch.dict("os.environ", {"JUPYTER_PLATFORM_DIRS": "1"})
6556

@@ -68,18 +59,23 @@
6859
prefer_env = patch.dict("os.environ", {"JUPYTER_PREFER_ENV_PATH": "True"})
6960
prefer_user = patch.dict("os.environ", {"JUPYTER_PREFER_ENV_PATH": "False"})
7061

71-
resetenv = patch.dict(os.environ)
72-
73-
74-
def setup_module():
75-
resetenv.start()
62+
def setup_function():
63+
environment.start()
64+
for var in [
65+
"JUPYTER_PLATFORM_DIRS"
66+
"JUPYTER_CONFIG_DIR",
67+
"JUPYTER_DATA_DIR",
68+
"JUPYTER_RUNTIME_DIR",
69+
"JUPYTER_PATH",
70+
]:
71+
os.environ.pop(var, None)
7672
# For these tests, default to preferring the user-level over environment-level paths
7773
# Tests can override this preference using the prefer_env decorator/context manager
7874
os.environ["JUPYTER_PREFER_ENV_PATH"] = "no"
7975

8076

81-
def teardown_module():
82-
resetenv.stop()
77+
def teardown_function():
78+
environment.stop()
8379

8480

8581
def realpath(path):
@@ -272,14 +268,14 @@ def test_runtime_dir_linux():
272268

273269
def test_jupyter_path():
274270
system_path = ["system", "path"]
275-
with no_config_env, patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path):
271+
with patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path):
276272
path = jupyter_path()
277273
assert path[0] == jupyter_data_dir()
278274
assert path[-2:] == system_path
279275

280276

281277
def test_jupyter_path_user_site():
282-
with no_config_env, patch.object(site, "ENABLE_USER_SITE", True):
278+
with patch.object(site, "ENABLE_USER_SITE", True):
283279
path = jupyter_path()
284280

285281
# deduplicated expected values
@@ -297,7 +293,7 @@ def test_jupyter_path_user_site():
297293

298294

299295
def test_jupyter_path_no_user_site():
300-
with no_config_env, patch.object(site, "ENABLE_USER_SITE", False):
296+
with patch.object(site, "ENABLE_USER_SITE", False):
301297
path = jupyter_path()
302298
assert path[0] == jupyter_data_dir()
303299
assert path[1] == paths.ENV_JUPYTER_PATH[0]

0 commit comments

Comments
 (0)