Skip to content

Commit d1a9e96

Browse files
authored
Merge pull request #2725 from yarikoptic/bf-resource-monitor
ENH: enable/disable resource monitor in the fixture per test
2 parents 0ef261c + eed1ec8 commit d1a9e96

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

nipype/interfaces/base/tests/test_resource_monitor.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
from ... import utility as niu
1919

2020
# Try to enable the resource monitor
21-
config.enable_resource_monitor()
2221
run_profile = config.resource_monitor
2322

2423

24+
@pytest.fixture(scope="module")
25+
def use_resource_monitor():
26+
config.enable_resource_monitor()
27+
yield
28+
config.disable_resource_monitor()
29+
30+
2531
class UseResourcesInputSpec(CommandLineInputSpec):
2632
mem_gb = traits.Float(
2733
desc='Number of GB of RAM to use', argstr='-g %f', mandatory=True)
@@ -51,7 +57,7 @@ class UseResources(CommandLine):
5157
os.getenv('CI_SKIP_TEST', False), reason='disabled in CI tests')
5258
@pytest.mark.parametrize("mem_gb,n_procs", [(0.5, 3), (2.2, 8), (0.8, 4),
5359
(1.5, 1)])
54-
def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
60+
def test_cmdline_profiling(tmpdir, mem_gb, n_procs, use_resource_monitor):
5561
"""
5662
Test runtime profiler correctly records workflow RAM/CPUs consumption
5763
of a CommandLine-derived interface
@@ -73,7 +79,7 @@ def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
7379
True, reason='test disabled temporarily, until funcion profiling works')
7480
@pytest.mark.parametrize("mem_gb,n_procs", [(0.5, 3), (2.2, 8), (0.8, 4),
7581
(1.5, 1)])
76-
def test_function_profiling(tmpdir, mem_gb, n_procs):
82+
def test_function_profiling(tmpdir, mem_gb, n_procs, use_resource_monitor):
7783
"""
7884
Test runtime profiler correctly records workflow RAM/CPUs consumption
7985
of a Function interface

nipype/utils/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ def enable_resource_monitor(self):
291291
"""Sets the resource monitor on"""
292292
self.resource_monitor = True
293293

294+
def disable_resource_monitor(self):
295+
"""Sets the resource monitor off"""
296+
self.resource_monitor = False
297+
294298
def get_display(self):
295299
"""Returns the first display available"""
296300

0 commit comments

Comments
 (0)