Skip to content
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

tests/debug_composition: Use fixture to preserve environment #2987

Merged
merged 1 commit into from
Jun 28, 2024
Merged
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
25 changes: 17 additions & 8 deletions tests/llvm/test_debug_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
from psyneulink.core.components.mechanisms.processing.transfermechanism import TransferMechanism
from psyneulink.core.compositions.composition import Composition


@pytest.fixture(autouse=True)
def preserve_env():

# Save old debug env var
old_env = os.environ.get("PNL_LLVM_DEBUG")

yield

# Restore old debug env var and reset the debug configuration
if old_env is None:
del os.environ["PNL_LLVM_DEBUG"]
else:
os.environ["PNL_LLVM_DEBUG"] = old_env
pnlvm.debug._update()


debug_options = ["const_input=[[[7]]]", "const_input", "const_params", "const_data", "const_state",
"stat", "time_stat", "unaligned_copy"]
options_combinations = (";".join(c) for c in pytest.helpers.power_set(debug_options))
Expand All @@ -18,8 +35,6 @@
])
@pytest.mark.parametrize("debug_env", [comb for comb in options_combinations if comb.count("const_input") < 2])
def test_debug_comp(mode, debug_env):
# save old debug env var
old_env = os.environ.get("PNL_LLVM_DEBUG")
if debug_env is not None:
os.environ["PNL_LLVM_DEBUG"] = debug_env
pnlvm.debug._update()
Expand All @@ -32,12 +47,6 @@ def test_debug_comp(mode, debug_env):
inputs_dict = {A: [5]}
output1 = comp.run(inputs=inputs_dict, execution_mode=mode)
output2 = comp.run(inputs=inputs_dict, execution_mode=mode)
# restore old debug env var and cleanup the debug configuration
if old_env is None:
del os.environ["PNL_LLVM_DEBUG"]
else:
os.environ["PNL_LLVM_DEBUG"] = old_env
pnlvm.debug._update()

assert len(comp.results) == 2

Expand Down
Loading