Skip to content

Clear the test environment before each function run #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions jupyter_core/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@
resetenv = patch.dict(os.environ)


def setup_module():
def setup_function():
resetenv.start()
for var in [
"JUPYTER_CONFIG_DIR",
"JUPYTER_CONFIG_PATH",
"JUPYTER_DATA_DIR",
"JUPYTER_NO_CONFIG",
"JUPYTER_PATH",
"JUPYTER_PLATFORM_DIRS",
"JUPYTER_RUNTIME_DIR",
]:
os.environ.pop(var, None)


def teardown_module():
def teardown_function():
resetenv.stop()


Expand Down
37 changes: 18 additions & 19 deletions jupyter_core/tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@
{},
)

no_config_env = patch.dict(
"os.environ",
{
"JUPYTER_PLATFORM_DIRS": "",
"JUPYTER_CONFIG_DIR": "",
"JUPYTER_DATA_DIR": "",
"JUPYTER_RUNTIME_DIR": "",
"JUPYTER_PATH": "",
},
)
environment = patch.dict("os.environ")

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

Expand All @@ -68,18 +59,26 @@
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():
environment.start()
for var in [
"JUPYTER_CONFIG_DIR",
"JUPYTER_CONFIG_PATH",
"JUPYTER_DATA_DIR",
"JUPYTER_NO_CONFIG",
"JUPYTER_PATH",
"JUPYTER_PLATFORM_DIRS",
"JUPYTER_RUNTIME_DIR",
]:
os.environ.pop(var, None)
# 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():
environment.stop()


def realpath(path):
Expand Down Expand Up @@ -272,14 +271,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
Expand All @@ -297,7 +296,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]
Expand Down