From 2add9431ed300dd3db390bf725be148a008a05a4 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 7 Jan 2023 05:13:38 -0700 Subject: [PATCH] Clear the test environment before each function run See #231 --- jupyter_core/tests/test_paths.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/jupyter_core/tests/test_paths.py b/jupyter_core/tests/test_paths.py index d7d48e91..3774b8f0 100644 --- a/jupyter_core/tests/test_paths.py +++ b/jupyter_core/tests/test_paths.py @@ -68,18 +68,15 @@ prefer_env = patch.dict("os.environ", {"JUPYTER_PREFER_ENV_PATH": "True"}) prefer_user = patch.dict("os.environ", {"JUPYTER_PREFER_ENV_PATH": "False"}) -resetenv = patch.dict(os.environ) - - -def setup_module(): - resetenv.start() +def setup_function(): + no_config_env.start() # For these tests, default to preferring the user-level over environment-level paths # Tests can override this preference using the prefer_env decorator/context manager os.environ["JUPYTER_PREFER_ENV_PATH"] = "no" -def teardown_module(): - resetenv.stop() +def teardown_function(): + no_config_env.stop() def realpath(path): @@ -272,14 +269,14 @@ def test_runtime_dir_linux(): def test_jupyter_path(): system_path = ["system", "path"] - with no_config_env, patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path): + with patch.object(paths, "SYSTEM_JUPYTER_PATH", system_path): path = jupyter_path() assert path[0] == jupyter_data_dir() assert path[-2:] == system_path def test_jupyter_path_user_site(): - with no_config_env, patch.object(site, "ENABLE_USER_SITE", True): + with patch.object(site, "ENABLE_USER_SITE", True): path = jupyter_path() # deduplicated expected values @@ -297,7 +294,7 @@ def test_jupyter_path_user_site(): def test_jupyter_path_no_user_site(): - with no_config_env, patch.object(site, "ENABLE_USER_SITE", False): + with patch.object(site, "ENABLE_USER_SITE", False): path = jupyter_path() assert path[0] == jupyter_data_dir() assert path[1] == paths.ENV_JUPYTER_PATH[0]