diff --git a/nipype/interfaces/base/core.py b/nipype/interfaces/base/core.py index 6069c12041..31ae82be52 100644 --- a/nipype/interfaces/base/core.py +++ b/nipype/interfaces/base/core.py @@ -500,6 +500,7 @@ def run(self, cwd=None, ignore_exception=None, **inputs): platform=platform.platform(), hostname=platform.node(), version=self.version) + runtime_attrs = set(runtime.dictcopy()) mon_sp = None if enable_rm: @@ -540,6 +541,10 @@ def run(self, cwd=None, ignore_exception=None, **inputs): if not ignore_exception: raise finally: + if runtime is None or runtime_attrs - set(runtime.dictcopy()): + raise RuntimeError("{} interface failed to return valid " + "runtime object".format( + interface.__class__.__name__)) # This needs to be done always runtime.endTime = dt.isoformat(dt.utcnow()) timediff = parseutc(runtime.endTime) - parseutc(runtime.startTime) diff --git a/nipype/interfaces/base/tests/test_core.py b/nipype/interfaces/base/tests/test_core.py index fe1b3a227e..392d38706f 100644 --- a/nipype/interfaces/base/tests/test_core.py +++ b/nipype/interfaces/base/tests/test_core.py @@ -517,3 +517,29 @@ class OOPBadShell(nib.CommandLine): ci = OOPBadShell(command=script_name) with pytest.raises(IOError): ci.run() + + +def test_runtime_checks(): + class TestInterface(nib.BaseInterface): + class input_spec(nib.TraitedSpec): + a = nib.traits.Any() + class output_spec(nib.TraitedSpec): + b = nib.traits.Any() + + def _run_interface(self, runtime): + return runtime + + class NoRuntime(TestInterface): + def _run_interface(self, runtime): + return None + + class BrokenRuntime(TestInterface): + def _run_interface(self, runtime): + del runtime.__dict__['cwd'] + return runtime + + with pytest.raises(RuntimeError): + NoRuntime().run() + + with pytest.raises(RuntimeError): + BrokenRuntime().run()