Skip to content

ENH: enable/disable resource monitor in the fixture per test #2725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions nipype/interfaces/base/tests/test_resource_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
from ... import utility as niu

# Try to enable the resource monitor
config.enable_resource_monitor()
run_profile = config.resource_monitor


@pytest.fixture(scope="module")
def use_resource_monitor():
config.enable_resource_monitor()
yield
config.disable_resource_monitor()


class UseResourcesInputSpec(CommandLineInputSpec):
mem_gb = traits.Float(
desc='Number of GB of RAM to use', argstr='-g %f', mandatory=True)
Expand Down Expand Up @@ -51,7 +57,7 @@ class UseResources(CommandLine):
os.getenv('CI_SKIP_TEST', False), reason='disabled in CI tests')
@pytest.mark.parametrize("mem_gb,n_procs", [(0.5, 3), (2.2, 8), (0.8, 4),
(1.5, 1)])
def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
def test_cmdline_profiling(tmpdir, mem_gb, n_procs, use_resource_monitor):
"""
Test runtime profiler correctly records workflow RAM/CPUs consumption
of a CommandLine-derived interface
Expand All @@ -73,7 +79,7 @@ def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
True, reason='test disabled temporarily, until funcion profiling works')
@pytest.mark.parametrize("mem_gb,n_procs", [(0.5, 3), (2.2, 8), (0.8, 4),
(1.5, 1)])
def test_function_profiling(tmpdir, mem_gb, n_procs):
def test_function_profiling(tmpdir, mem_gb, n_procs, use_resource_monitor):
"""
Test runtime profiler correctly records workflow RAM/CPUs consumption
of a Function interface
Expand Down
4 changes: 4 additions & 0 deletions nipype/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def enable_resource_monitor(self):
"""Sets the resource monitor on"""
self.resource_monitor = True

def disable_resource_monitor(self):
"""Sets the resource monitor off"""
self.resource_monitor = False

def get_display(self):
"""Returns the first display available"""

Expand Down