From cbd4697d4507f06fff38236c41ccb26568df44a4 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Tue, 12 Oct 2021 13:58:39 -0700 Subject: [PATCH] Add setup and teardown functions so tests pass even when JUPYTER_PREFER_ENV_PATH is defined in the environment --- jupyter_core/tests/test_command.py | 9 +++++++++ jupyter_core/tests/test_paths.py | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/jupyter_core/tests/test_command.py b/jupyter_core/tests/test_command.py index 4c8c7d0f..f7e4b7d7 100644 --- a/jupyter_core/tests/test_command.py +++ b/jupyter_core/tests/test_command.py @@ -17,6 +17,15 @@ ) +resetenv = patch.dict(os.environ) + +def setup_module(): + resetenv.start() + os.environ.pop('JUPYTER_PREFER_ENV_PATH') + +def teardown_module(): + resetenv.stop() + def get_jupyter_output(cmd): """Get output of a jupyter command""" if not isinstance(cmd, list): diff --git a/jupyter_core/tests/test_paths.py b/jupyter_core/tests/test_paths.py index e59f46c4..6c5a49d3 100644 --- a/jupyter_core/tests/test_paths.py +++ b/jupyter_core/tests/test_paths.py @@ -48,6 +48,17 @@ jupyter_config_env = '/jupyter-cfg' config_env = patch.dict('os.environ', {'JUPYTER_CONFIG_DIR': jupyter_config_env}) +prefer_env = patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'True'}) + +resetenv = patch.dict(os.environ) + +def setup_module(): + resetenv.start() + os.environ.pop('JUPYTER_PREFER_ENV_PATH') + +def teardown_module(): + resetenv.stop() + def realpath(path): @@ -55,7 +66,6 @@ def realpath(path): home_jupyter = realpath('~/.jupyter') - def test_envset(): true_values = ['', 'True', 'on', 'yes', 'Y', '1', 'anything'] false_values = ['n', 'No', 'N', 'fAlSE', '0', '0.0', 'Off'] @@ -199,7 +209,7 @@ def test_jupyter_path_no_user_site(): assert path[1] == paths.ENV_JUPYTER_PATH[0] def test_jupyter_path_prefer_env(): - with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}): + with prefer_env: path = jupyter_path() assert path[0] == paths.ENV_JUPYTER_PATH[0] assert path[1] == jupyter_data_dir() @@ -241,7 +251,7 @@ def test_jupyter_config_path_no_user_site(): def test_jupyter_config_path_prefer_env(): - with patch.dict('os.environ', {'JUPYTER_PREFER_ENV_PATH': 'true'}): + with prefer_env: path = jupyter_config_path() assert path[0] == paths.ENV_CONFIG_PATH[0] assert path[1] == jupyter_config_dir()