Skip to content

Commit 49d1a95

Browse files
committed
simplified test construct
1 parent fe60dfc commit 49d1a95

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,8 @@ def _node_runner(self, nodes, updatehash=False):
11281128
err = None
11291129
try:
11301130
node.run(updatehash=updatehash)
1131-
except Exception as e:
1132-
if sys.version < 3:
1133-
err = e
1134-
else:
1135-
err = str(e)
1131+
except Exception as this_err:
1132+
err = this_err
11361133
if str2bool(self.config['execution']['stop_on_first_crash']):
11371134
raise
11381135
finally:

nipype/pipeline/engine/tests/test_utils.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
from copy import deepcopy
1111
from shutil import rmtree
12+
import pytest
1213

1314
from ... import engine as pe
1415
from ....interfaces import base as nib
@@ -352,13 +353,8 @@ def myfunction(string):
352353
node.config = deepcopy(config._sections)
353354
node.config['execution']['stop_on_first_crash'] = True
354355
node.base_dir = str(tmpdir)
355-
356-
error_raised = False
357-
try:
356+
with pytest.raises(TypeError):
358357
node.run()
359-
except TypeError as e:
360-
error_raised = True
361-
assert error_raised
362358

363359

364360
def test_mapnode_crash2(tmpdir):
@@ -374,12 +370,8 @@ def myfunction(string):
374370
node.inputs.WRONG = ['string' + str(i) for i in range(3)]
375371
node.base_dir = str(tmpdir)
376372

377-
error_raised = False
378-
try:
373+
with pytest.raises(Exception):
379374
node.run()
380-
except Exception as e:
381-
error_raised = True
382-
assert error_raised
383375

384376

385377
def test_mapnode_crash3(tmpdir):
@@ -395,13 +387,7 @@ def myfunction(string):
395387

396388
node.inputs.WRONG = ['string' + str(i) for i in range(3)]
397389
wf = pe.Workflow('testmapnodecrash')
398-
wf.config['crashdump_dir'] = str(tmpdir)
399390
wf.add_nodes([node])
400391
wf.base_dir = str(tmpdir)
401-
402-
error_raised = False
403-
try:
404-
wf.run()
405-
except RuntimeError as e:
406-
error_raised = True
407-
assert error_raised
392+
with pytest.raises(RuntimeError):
393+
wf.run(plugin='Linear')

0 commit comments

Comments
 (0)