Skip to content

Commit eb65690

Browse files
Clear the test environment before each function run (#333)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6b4df54 commit eb65690

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

jupyter_core/tests/test_command.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@
2121
resetenv = patch.dict(os.environ)
2222

2323

24-
def setup_module():
24+
def setup_function():
2525
resetenv.start()
26+
for var in [
27+
"JUPYTER_CONFIG_DIR",
28+
"JUPYTER_CONFIG_PATH",
29+
"JUPYTER_DATA_DIR",
30+
"JUPYTER_NO_CONFIG",
31+
"JUPYTER_PATH",
32+
"JUPYTER_PLATFORM_DIRS",
33+
"JUPYTER_RUNTIME_DIR",
34+
]:
35+
os.environ.pop(var, None)
2636

2737

28-
def teardown_module():
38+
def teardown_function():
2939
resetenv.stop()
3040

3141

jupyter_core/tests/test_paths.py

Lines changed: 18 additions & 19 deletions
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,26 @@
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-
7362

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

8079

81-
def teardown_module():
82-
resetenv.stop()
80+
def teardown_function():
81+
environment.stop()
8382

8483

8584
def realpath(path):
@@ -272,14 +271,14 @@ def test_runtime_dir_linux():
272271

273272
def test_jupyter_path():
274273
system_path = ["system", "path"]
275-
with no_config_env, patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path):
274+
with patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path):
276275
path = jupyter_path()
277276
assert path[0] == jupyter_data_dir()
278277
assert path[-2:] == system_path
279278

280279

281280
def test_jupyter_path_user_site():
282-
with no_config_env, patch.object(site, "ENABLE_USER_SITE", True):
281+
with patch.object(site, "ENABLE_USER_SITE", True):
283282
path = jupyter_path()
284283

285284
# deduplicated expected values
@@ -297,7 +296,7 @@ def test_jupyter_path_user_site():
297296

298297

299298
def test_jupyter_path_no_user_site():
300-
with no_config_env, patch.object(site, "ENABLE_USER_SITE", False):
299+
with patch.object(site, "ENABLE_USER_SITE", False):
301300
path = jupyter_path()
302301
assert path[0] == jupyter_data_dir()
303302
assert path[1] == paths.ENV_JUPYTER_PATH[0]

0 commit comments

Comments
 (0)