Skip to content

Commit fbcd50c

Browse files
committed
Disable trace output by default in tests
This is usually not desired and requires frequent mocking of stdout or repeated calls to `init_config` disabling "trace"
1 parent 8de5e93 commit fbcd50c

File tree

3 files changed

+17
-42
lines changed

3 files changed

+17
-42
lines changed

test/framework/run.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,6 @@ def test_run_shell_cmd_fail(self):
541541
def handler(signum, _):
542542
raise RuntimeError("Signal handler called with signal %s" % signum)
543543

544-
# disable trace output for this test (so stdout remains empty)
545-
update_build_option('trace', False)
546-
547544
orig_sigalrm_handler = signal.getsignal(signal.SIGALRM)
548545

549546
try:
@@ -837,8 +834,6 @@ def test_run_cmd_trace(self):
837834
regex = re.compile('\n'.join(pattern))
838835
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
839836

840-
init_config(build_options={'trace': False})
841-
842837
self.mock_stdout(True)
843838
self.mock_stderr(True)
844839
(out, ec) = run_cmd("echo hello")
@@ -851,8 +846,6 @@ def test_run_cmd_trace(self):
851846
self.assertTrue(stderr.strip().startswith("WARNING: Deprecated functionality"))
852847
self.assertEqual(stdout, '')
853848

854-
init_config(build_options={'trace': True})
855-
856849
# also test with command that is fed input via stdin
857850
self.mock_stdout(True)
858851
self.mock_stderr(True)
@@ -869,8 +862,6 @@ def test_run_cmd_trace(self):
869862
regex = re.compile('\n'.join(pattern))
870863
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
871864

872-
init_config(build_options={'trace': False})
873-
874865
self.mock_stdout(True)
875866
self.mock_stderr(True)
876867
(out, ec) = run_cmd('cat', inp='hello')
@@ -925,8 +916,6 @@ def test_run_shell_cmd_trace(self):
925916
regex = re.compile('\n'.join(pattern))
926917
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
927918

928-
init_config(build_options={'trace': False})
929-
930919
self.mock_stdout(True)
931920
self.mock_stderr(True)
932921
res = run_shell_cmd("echo hello")
@@ -939,8 +928,6 @@ def test_run_shell_cmd_trace(self):
939928
self.assertEqual(stderr, '')
940929
self.assertEqual(stdout, '')
941930

942-
init_config(build_options={'trace': True})
943-
944931
# trace output can be disabled on a per-command basis via 'hidden' option
945932
for trace in (True, False):
946933
init_config(build_options={'trace': trace})
@@ -2059,9 +2046,6 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
20592046
write_file(hooks_file, hooks_file_txt)
20602047
update_build_option('hooks', hooks_file)
20612048

2062-
# disable trace output to make checking of generated output produced by hooks easier
2063-
update_build_option('trace', False)
2064-
20652049
with self.mocked_stdout_stderr():
20662050
run_cmd("make")
20672051
stdout = self.get_stdout()
@@ -2133,9 +2117,6 @@ def post_run_shell_cmd_hook(cmd, *args, **kwargs):
21332117
write_file(hooks_file, hooks_file_txt)
21342118
update_build_option('hooks', hooks_file)
21352119

2136-
# disable trace output to make checking of generated output produced by hooks easier
2137-
update_build_option('trace', False)
2138-
21392120
with self.mocked_stdout_stderr():
21402121
run_shell_cmd("make")
21412122
stdout = self.get_stdout()

test/framework/toolchain.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,8 +2023,7 @@ def test_old_new_iccifort(self):
20232023
scalapack_mt_shared_libs_fosscuda = scalapack_mt_static_libs_fosscuda.replace('.a', '.' + shlib_ext)
20242024

20252025
tc = self.get_toolchain('fosscuda', version='2018a')
2026-
with self.mocked_stdout_stderr():
2027-
tc.prepare()
2026+
tc.prepare()
20282027
self.assertEqual(os.environ['BLAS_SHARED_LIBS'], blas_shared_libs_fosscuda)
20292028
self.assertEqual(os.environ['BLAS_STATIC_LIBS'], blas_static_libs_fosscuda)
20302029
self.assertEqual(os.environ['BLAS_MT_SHARED_LIBS'], blas_mt_shared_libs_fosscuda)
@@ -2116,8 +2115,7 @@ def test_old_new_iccifort(self):
21162115
self.modtool.purge()
21172116

21182117
tc = self.get_toolchain('intel', version='2018a')
2119-
with self.mocked_stdout_stderr():
2120-
tc.prepare()
2118+
tc.prepare()
21212119
self.assertEqual(os.environ.get('BLAS_SHARED_LIBS', "(not set)"), blas_shared_libs_intel4)
21222120
self.assertEqual(os.environ.get('BLAS_STATIC_LIBS', "(not set)"), blas_static_libs_intel4)
21232121
self.assertEqual(os.environ.get('LAPACK_SHARED_LIBS', "(not set)"), blas_shared_libs_intel4)
@@ -2130,22 +2128,19 @@ def test_old_new_iccifort(self):
21302128
self.modtool.purge()
21312129

21322130
tc = self.get_toolchain('intel', version='2012a')
2133-
with self.mocked_stdout_stderr():
2134-
tc.prepare()
2131+
tc.prepare()
21352132
self.assertEqual(os.environ.get('LIBBLAS_MT', "(not set)"), libblas_mt_intel3)
21362133
self.assertIn(libscalack_intel3, os.environ['LIBSCALAPACK'])
21372134
self.modtool.purge()
21382135

21392136
tc = self.get_toolchain('intel', version='2018a')
2140-
with self.mocked_stdout_stderr():
2141-
tc.prepare()
2137+
tc.prepare()
21422138
self.assertEqual(os.environ.get('LIBBLAS_MT', "(not set)"), libblas_mt_intel4)
21432139
self.assertIn(libscalack_intel4, os.environ['LIBSCALAPACK'])
21442140
self.modtool.purge()
21452141

21462142
tc = self.get_toolchain('intel', version='2012a')
2147-
with self.mocked_stdout_stderr():
2148-
tc.prepare()
2143+
tc.prepare()
21492144
self.assertEqual(os.environ.get('LIBBLAS_MT', "(not set)"), libblas_mt_intel3)
21502145
self.assertIn(libscalack_intel3, os.environ['LIBSCALAPACK'])
21512146
self.modtool.purge()
@@ -2154,15 +2149,13 @@ def test_old_new_iccifort(self):
21542149
tc = self.get_toolchain('intel', version='2018a')
21552150
opts = {'i8': True}
21562151
tc.set_options(opts)
2157-
with self.mocked_stdout_stderr():
2158-
tc.prepare()
2152+
tc.prepare()
21592153
self.assertIn(libscalack_intel4, os.environ['LIBSCALAPACK'])
21602154
self.modtool.purge()
21612155

21622156
tc = self.get_toolchain('fosscuda', version='2018a')
21632157
tc.set_options({'openmp': True})
2164-
with self.mocked_stdout_stderr():
2165-
tc.prepare()
2158+
tc.prepare()
21662159
self.assertEqual(os.environ['BLAS_SHARED_LIBS'], blas_shared_libs_fosscuda)
21672160
self.assertEqual(os.environ['BLAS_STATIC_LIBS'], blas_static_libs_fosscuda)
21682161
self.assertEqual(os.environ['BLAS_MT_SHARED_LIBS'], blas_mt_shared_libs_fosscuda)

test/framework/utilities.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def setUp(self):
137137
# disable progress bars when running the tests,
138138
# since it messes with test suite progress output when test installations are performed
139139
os.environ['EASYBUILD_DISABLE_SHOW_PROGRESS_BAR'] = '1'
140+
# Also disable trace output to keep stdout clean during tests
141+
os.environ['EASYBUILD_DISABLE_TRACE'] = '1'
140142

141143
# Store the environment as setup (including the above paths) for tests to restore
142144
self.orig_environ = copy.deepcopy(os.environ)
@@ -487,25 +489,24 @@ def init_config(args=None, build_options=None, with_include=True, clear_caches=T
487489
eb_go = eboptions.parse_options(args=args, with_include=with_include)
488490
config.init(eb_go.options, eb_go.get_options_by_section('config'))
489491

490-
# initialize build options
491-
if build_options is None:
492-
build_options = {}
493-
494-
default_build_options = {
492+
# initialize default build options
493+
options = {
495494
'extended_dry_run': False,
496495
'external_modules_metadata': ConfigObj(),
497496
'local_var_naming_check': 'error',
497+
'show_progress_bar': False,
498498
'silence_deprecation_warnings': eb_go.options.silence_deprecation_warnings,
499499
'suffix_modules_path': GENERAL_CLASS,
500+
'trace': False,
500501
'unit_testing_mode': True,
501502
'valid_module_classes': module_classes(),
502503
'valid_stops': [x[0] for x in EasyBlock.get_steps()],
503504
}
504-
for key in default_build_options:
505-
if key not in build_options:
506-
build_options[key] = default_build_options[key]
507505

508-
config.init_build_options(build_options=build_options)
506+
if build_options is not None:
507+
options.update(build_options)
508+
509+
config.init_build_options(build_options=options)
509510

510511
return eb_go.options
511512

0 commit comments

Comments
 (0)