Skip to content

Commit b67226e

Browse files
committed
TEST: Fix plugin invocation, use an initializer that can be verified
1 parent 841dcf8 commit b67226e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

niworkflows/engine/tests/test_plugin.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ def test_plugin_defaults(workflow, caplog):
7272
def test_plugin_args_noconfig(workflow, caplog):
7373
"""Test the plugin works with typical nipype arguments."""
7474
caplog.set_level(logging.CRITICAL, logger="nipype.workflow")
75-
workflow.run(
76-
plugin=MultiProcPlugin(),
77-
plugin_args={"n_procs": 2, "memory_gb": 0.1},
78-
)
75+
workflow.run(plugin=MultiProcPlugin(plugin_args={"n_procs": 2, "memory_gb": 0.1}))
76+
7977

78+
def touch_file(file_path):
79+
"""Module-level functions play more nicely with multiprocessing."""
80+
with open(file_path, "w") as f:
81+
f.write("flag")
8082

81-
def test_plugin_app_config(workflow, caplog, capsys):
83+
84+
def test_plugin_app_config(tmp_path, workflow, caplog):
8285
"""Test the plugin works with a nipreps-style configuration."""
8386

84-
def init_print():
85-
print("Custom init")
87+
init_flag = tmp_path / "init_flag.txt"
8688

8789
app_config = SimpleNamespace(
88-
environment=SimpleNamespace(total_memory_gb=1),
89-
_process_initializer=init_print(),
90-
file_path='/does/not/need/to/exist/for/testing',
90+
environment=SimpleNamespace(total_memory=1),
91+
_process_initializer=touch_file,
92+
file_path=init_flag,
9193
)
92-
caplog.set_level(logging.CRITICAL, logger="nipype.workflow")
94+
caplog.set_level(logging.INFO, logger="nipype.workflow")
9395
workflow.run(
94-
plugin=MultiProcPlugin(),
95-
plugin_args={"n_procs": 2, "app_config": app_config},
96+
plugin=MultiProcPlugin(plugin_args={"n_procs": 2, "app_config": app_config})
9697
)
9798

98-
captured = capsys.readouterr()
99-
assert "Custom init" in captured.out
99+
assert init_flag.exists() and init_flag.read_text() == "flag"

0 commit comments

Comments
 (0)