Skip to content

Commit 02d1500

Browse files
authored
Merge pull request #3239 from effigies/fix/no_et_38_failure
FIX: test_no_et hanging on Python 3.8
2 parents c71b8ac + 7400725 commit 02d1500

File tree

2 files changed

+27
-39
lines changed

2 files changed

+27
-39
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ install:
7171
script:
7272
- |
7373
if [ "$CHECK_TYPE" = "test" ]; then
74-
py.test -v --cov nipype --cov-config .coveragerc --cov-report xml:cov.xml -c nipype/pytest.ini --doctest-modules nipype -n auto
74+
py.test -sv --cov nipype --cov-config .coveragerc --cov-report xml:cov.xml -c nipype/pytest.ini --doctest-modules nipype -n 2
7575
fi
7676
- |
7777
if [ "$CHECK_TYPE" = "specs" ]; then

nipype/tests/test_nipype.py

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _check_no_et():
4141
return et
4242

4343

44-
def test_no_et(tmp_path):
44+
def test_no_et_bare(tmp_path):
4545
from unittest.mock import patch
4646
from nipype.pipeline import engine as pe
4747
from nipype.interfaces import utility as niu
@@ -70,42 +70,30 @@ def test_no_et(tmp_path):
7070
res = wf1.run()
7171
assert next(iter(res.nodes)).result.outputs.out == et
7272

73-
# MultiProc run - environment initialized with NIPYPE_NO_ET
74-
wf2 = pe.Workflow(name="wf2", base_dir=str(tmp_path))
75-
wf2.add_nodes([pe.Node(niu.Function(function=_check_no_et), name="n")])
76-
res = wf2.run(plugin="MultiProc", plugin_args={"n_procs": 1})
77-
assert next(iter(res.nodes)).result.outputs.out is False
78-
79-
# LegacyMultiProc run - environment initialized with NIPYPE_NO_ET
80-
wf3 = pe.Workflow(name="wf3", base_dir=str(tmp_path))
81-
wf3.add_nodes([pe.Node(niu.Function(function=_check_no_et), name="n")])
82-
res = wf3.run(plugin="LegacyMultiProc", plugin_args={"n_procs": 1})
83-
assert next(iter(res.nodes)).result.outputs.out is False
84-
85-
# run_without_submitting - environment not set
86-
wf4 = pe.Workflow(name="wf4", base_dir=str(tmp_path))
87-
wf4.add_nodes(
88-
[
89-
pe.Node(
90-
niu.Function(function=_check_no_et),
91-
run_without_submitting=True,
92-
name="n",
93-
)
94-
]
95-
)
96-
res = wf4.run(plugin="MultiProc", plugin_args={"n_procs": 1})
97-
assert next(iter(res.nodes)).result.outputs.out == et
9873

99-
# run_without_submitting - environment not set
100-
wf5 = pe.Workflow(name="wf5", base_dir=str(tmp_path))
101-
wf5.add_nodes(
102-
[
103-
pe.Node(
104-
niu.Function(function=_check_no_et),
105-
run_without_submitting=True,
106-
name="n",
107-
)
108-
]
74+
@pytest.mark.parametrize("plugin", ("MultiProc", "LegacyMultiProc"))
75+
@pytest.mark.parametrize("run_without_submitting", (True, False))
76+
def test_no_et_multiproc(tmp_path, plugin, run_without_submitting):
77+
from unittest.mock import patch
78+
from nipype.pipeline import engine as pe
79+
from nipype.interfaces import utility as niu
80+
from nipype.interfaces.base import BaseInterface
81+
82+
et = os.getenv("NIPYPE_NO_ET") is None
83+
84+
# Multiprocessing runs initialize new processes with NIPYPE_NO_ET
85+
# This does not apply to unsubmitted jobs, run by the main thread
86+
expectation = et if run_without_submitting else False
87+
88+
# Pytest doesn't trigger this, so let's pretend it's there
89+
with patch.object(BaseInterface, "_etelemetry_version_data", {}):
90+
91+
wf = pe.Workflow(name="wf2", base_dir=str(tmp_path))
92+
n = pe.Node(
93+
niu.Function(function=_check_no_et),
94+
run_without_submitting=run_without_submitting,
95+
name="n",
10996
)
110-
res = wf5.run(plugin="LegacyMultiProc", plugin_args={"n_procs": 1})
111-
assert next(iter(res.nodes)).result.outputs.out == et
97+
wf.add_nodes([n])
98+
res = wf.run(plugin=plugin, plugin_args={"n_procs": 1})
99+
assert next(iter(res.nodes)).result.outputs.out is expectation

0 commit comments

Comments
 (0)