diff --git a/easybuild/_deprecated.py b/easybuild/_deprecated.py index f22ad0ba53..69920b9318 100644 --- a/easybuild/_deprecated.py +++ b/easybuild/_deprecated.py @@ -96,7 +96,7 @@ def cache_aware_func(cmd, *args, **kwargs): return cache_aware_func -def get_output_from_process(proc, read_size=None, asynchronous=False): +def get_output_from_process(proc, read_size=None, asynchronous=False, print_deprecation_warning=True): """ Get output from running process (that was opened with subprocess.Popen). @@ -105,6 +105,9 @@ def get_output_from_process(proc, read_size=None, asynchronous=False): :param asynchronous: get output asynchronously """ + if print_deprecation_warning: + _log.deprecated("get_output_from_process is deprecated, you should stop using it", '6.0') + if asynchronous: # e=False is set to avoid raising an exception when command has completed; # that's needed to ensure we get all output, @@ -256,7 +259,8 @@ def run_cmd(cmd, log_ok=True, log_all=False, simple=False, inp=None, regexp=True return (proc, cmd, cwd, start_time, cmd_log) else: return complete_cmd(proc, cmd, cwd, start_time, cmd_log, log_ok=log_ok, log_all=log_all, simple=simple, - regexp=regexp, stream_output=stream_output, trace=trace, with_hook=with_hooks) + regexp=regexp, stream_output=stream_output, trace=trace, with_hook=with_hooks, + print_deprecation_warning=False) def check_async_cmd(proc, cmd, owd, start_time, cmd_log, fail_on_error=True, output_read_size=1024, output=''): @@ -275,11 +279,13 @@ def check_async_cmd(proc, cmd, owd, start_time, cmd_log, fail_on_error=True, out :result: dict value with result of the check (boolean 'done', 'exit_code', 'output') """ + _log.deprecated("check_async_cmd is deprecated, you should stop using it", '6.0') + # use small read size, to avoid waiting for a long time until sufficient output is produced if output_read_size: if not isinstance(output_read_size, int) or output_read_size < 0: raise EasyBuildError("Number of output bytes to read should be a positive integer value (or zero)") - add_out = get_output_from_process(proc, read_size=output_read_size) + add_out = get_output_from_process(proc, read_size=output_read_size, print_deprecation_warning=False) _log.debug("Additional output from asynchronous command '%s': %s" % (cmd, add_out)) output += add_out @@ -290,7 +296,8 @@ def check_async_cmd(proc, cmd, owd, start_time, cmd_log, fail_on_error=True, out else: _log.debug("Asynchronous command '%s' completed!", cmd) output, _ = complete_cmd(proc, cmd, owd, start_time, cmd_log, output=output, - simple=False, trace=False, log_ok=fail_on_error) + simple=False, trace=False, log_ok=fail_on_error, + print_deprecation_warning=False) done = True res = { @@ -302,7 +309,8 @@ def check_async_cmd(proc, cmd, owd, start_time, cmd_log, fail_on_error=True, out def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False, simple=False, - regexp=True, stream_output=None, trace=True, output='', with_hook=True): + regexp=True, stream_output=None, trace=True, output='', with_hook=True, + print_deprecation_warning=True): """ Complete running of command represented by passed subprocess.Popen instance. @@ -319,6 +327,10 @@ def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False :param trace: print command being executed as part of trace output :param with_hook: trigger post run_shell_cmd hooks (if defined) """ + + if print_deprecation_warning: + _log.deprecated("complete_cmd is deprecated, you should stop using it", '6.0') + # use small read size when streaming output, to make it stream more fluently # read size should not be too small though, to avoid too much overhead if stream_output: @@ -333,7 +345,7 @@ def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False while ec is None: # need to read from time to time. # - otherwise the stdout/stderr buffer gets filled and it all stops working - output = get_output_from_process(proc, read_size=read_size) + output = get_output_from_process(proc, read_size=read_size, print_deprecation_warning=False) if cmd_log: cmd_log.write(output) if stream_output: @@ -342,7 +354,7 @@ def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False ec = proc.poll() # read remaining data (all of it) - output = get_output_from_process(proc) + output = get_output_from_process(proc, print_deprecation_warning=False) finally: proc.stdout.close() @@ -370,7 +382,7 @@ def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False except OSError as err: raise EasyBuildError("Failed to return to %s after executing command: %s", owd, err) - return parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp) + return parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp, print_deprecation_warning=False) def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, regexp=True, std_qa=None, path=None, @@ -389,6 +401,9 @@ def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, re :param maxhits: maximum number of cycles (seconds) without being able to find a known question :param trace: print command being executed as part of trace output """ + + _log.deprecated("run_cmd_qa is deprecated, use run_shell_cmd from easybuild.tools.run instead", '6.0') + cwd = os.getcwd() if not isinstance(cmd, str) and len(cmd) > 1: @@ -549,7 +564,7 @@ def get_proc(): # need to read from time to time. # - otherwise the stdout/stderr buffer gets filled and it all stops working try: - out = get_output_from_process(proc, asynchronous=True) + out = get_output_from_process(proc, asynchronous=True, print_deprecation_warning=False) if cmd_log: cmd_log.write(out) @@ -622,7 +637,7 @@ def get_proc(): # Process stopped. Read all remaining data try: if proc.stdout: - out = get_output_from_process(proc) + out = get_output_from_process(proc, print_deprecation_warning=False) stdout_err += out if cmd_log: cmd_log.write(out) @@ -644,10 +659,10 @@ def get_proc(): except OSError as err: raise EasyBuildError("Failed to return to %s after executing command: %s", cwd, err) - return parse_cmd_output(cmd, stdout_err, ec, simple, log_all, log_ok, regexp) + return parse_cmd_output(cmd, stdout_err, ec, simple, log_all, log_ok, regexp, print_deprecation_warning=False) -def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp): +def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp, print_deprecation_warning=True): """ Parse command output and construct return value. :param cmd: executed command @@ -658,6 +673,10 @@ def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp): :param log_ok: only run output/exit code for failing commands (exit code non-zero) :param regexp: regex used to check the output for errors; if True it will use the default (see parse_log_for_error) """ + + if print_deprecation_warning: + _log.deprecated("parse_cmd_output is deprecated, you should stop using it", '6.0') + if strictness == IGNORE: check_ec = False fail_on_error_match = False @@ -688,7 +707,7 @@ def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp): # parse the stdout/stderr for errors when strictness dictates this or when regexp is passed in if fail_on_error_match or regexp: - res = parse_log_for_error(stdouterr, regexp, stdout=False) + res = parse_log_for_error(stdouterr, regexp, stdout=False, print_deprecation_warning=False) if res: errors = "\n\t" + "\n\t".join([r[0] for r in res]) error_str = "error" if len(res) == 1 else "errors" @@ -709,13 +728,17 @@ def parse_cmd_output(cmd, stdouterr, ec, simple, log_all, log_ok, regexp): return (stdouterr, ec) -def parse_log_for_error(txt, regExp=None, stdout=True, msg=None): +def parse_log_for_error(txt, regExp=None, stdout=True, msg=None, print_deprecation_warning=True): """ txt is multiline string. - in memory regExp is a one-line regular expression - default """ + + if print_deprecation_warning: + _log.deprecated("parse_log_for_error is deprecated, you should stop using it", '6.0') + global errors_found_in_log if regExp and isinstance(regExp, bool): @@ -744,7 +767,7 @@ def parse_log_for_error(txt, regExp=None, stdout=True, msg=None): return res -def extract_errors_from_log(log_txt, reg_exps): +def extract_errors_from_log(log_txt, reg_exps, print_deprecation_warning=True): """ Check provided string (command output) for messages matching specified regular expressions, and return 2-tuple with list of warnings and errors. @@ -753,6 +776,10 @@ def extract_errors_from_log(log_txt, reg_exps): or tuple of regular expression and action (any of [IGNORE, WARN, ERROR]) :return: (warnings, errors) as lists of lines containing a match """ + + if print_deprecation_warning: + _log.deprecated("extract_errors_from_log is deprecated, you should stop using it", '6.0') + actions = (IGNORE, WARN, ERROR) # promote single string value to list, since code below expects a list @@ -799,8 +826,11 @@ def check_log_for_errors(log_txt, reg_exps): :param reg_exps: List of: regular expressions (as strings) to error on, or tuple of regular expression and action (any of [IGNORE, WARN, ERROR]) """ + + _log.deprecated("check_log_for_errors is deprecated, you should stop using it", '6.0') + global errors_found_in_log - warnings, errors = extract_errors_from_log(log_txt, reg_exps) + warnings, errors = extract_errors_from_log(log_txt, reg_exps, print_deprecation_warning=False) errors_found_in_log += len(warnings) + len(errors) if warnings: diff --git a/test/framework/run.py b/test/framework/run.py index 2e0837e225..308c086f94 100644 --- a/test/framework/run.py +++ b/test/framework/run.py @@ -76,6 +76,9 @@ def tearDown(self): def test_get_output_from_process(self): """Test for get_output_from_process utility function.""" + # use of get_output_from_process is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + @contextlib.contextmanager def get_proc(cmd, asynchronous=False): if asynchronous: @@ -92,53 +95,58 @@ def get_proc(cmd, asynchronous=False): subprocess_terminate(proc, timeout=1) # get all output at once - with get_proc("echo hello") as proc: - out = get_output_from_process(proc) - self.assertEqual(out, 'hello\n') + with self.mocked_stdout_stderr(): + with get_proc("echo hello") as proc: + out = get_output_from_process(proc) + self.assertEqual(out, 'hello\n') # first get 100 bytes, then get the rest all at once - with get_proc("echo hello") as proc: - out = get_output_from_process(proc, read_size=100) - self.assertEqual(out, 'hello\n') - out = get_output_from_process(proc) - self.assertEqual(out, '') + with self.mocked_stdout_stderr(): + with get_proc("echo hello") as proc: + out = get_output_from_process(proc, read_size=100) + self.assertEqual(out, 'hello\n') + out = get_output_from_process(proc) + self.assertEqual(out, '') # get output in small bits, keep trying to get output (which shouldn't fail) - with get_proc("echo hello") as proc: - out = get_output_from_process(proc, read_size=1) - self.assertEqual(out, 'h') - out = get_output_from_process(proc, read_size=3) - self.assertEqual(out, 'ell') - out = get_output_from_process(proc, read_size=2) - self.assertEqual(out, 'o\n') - out = get_output_from_process(proc, read_size=1) - self.assertEqual(out, '') - out = get_output_from_process(proc, read_size=10) - self.assertEqual(out, '') - out = get_output_from_process(proc) - self.assertEqual(out, '') + with self.mocked_stdout_stderr(): + with get_proc("echo hello") as proc: + out = get_output_from_process(proc, read_size=1) + self.assertEqual(out, 'h') + out = get_output_from_process(proc, read_size=3) + self.assertEqual(out, 'ell') + out = get_output_from_process(proc, read_size=2) + self.assertEqual(out, 'o\n') + out = get_output_from_process(proc, read_size=1) + self.assertEqual(out, '') + out = get_output_from_process(proc, read_size=10) + self.assertEqual(out, '') + out = get_output_from_process(proc) + self.assertEqual(out, '') # can also get output asynchronously (read_size is *ignored* in that case) async_cmd = "echo hello; read reply; echo $reply" - with get_proc(async_cmd, asynchronous=True) as proc: - out = get_output_from_process(proc, asynchronous=True) - self.assertEqual(out, 'hello\n') - asyncprocess.send_all(proc, 'test123\n') - out = get_output_from_process(proc) - self.assertEqual(out, 'test123\n') + with self.mocked_stdout_stderr(): + with get_proc(async_cmd, asynchronous=True) as proc: + out = get_output_from_process(proc, asynchronous=True) + self.assertEqual(out, 'hello\n') + asyncprocess.send_all(proc, 'test123\n') + out = get_output_from_process(proc) + self.assertEqual(out, 'test123\n') - with get_proc(async_cmd, asynchronous=True) as proc: - out = get_output_from_process(proc, asynchronous=True, read_size=1) - # read_size is ignored when getting output asynchronously, we're getting more than 1 byte! - self.assertEqual(out, 'hello\n') - asyncprocess.send_all(proc, 'test123\n') - out = get_output_from_process(proc, read_size=3) - self.assertEqual(out, 'tes') - out = get_output_from_process(proc, read_size=2) - self.assertEqual(out, 't1') - out = get_output_from_process(proc) - self.assertEqual(out, '23\n') + with self.mocked_stdout_stderr(): + with get_proc(async_cmd, asynchronous=True) as proc: + out = get_output_from_process(proc, asynchronous=True, read_size=1) + # read_size is ignored when getting output asynchronously, we're getting more than 1 byte! + self.assertEqual(out, 'hello\n') + asyncprocess.send_all(proc, 'test123\n') + out = get_output_from_process(proc, read_size=3) + self.assertEqual(out, 'tes') + out = get_output_from_process(proc, read_size=2) + self.assertEqual(out, 't1') + out = get_output_from_process(proc) + self.assertEqual(out, '23\n') def test_run_cmd(self): """Basic test for run_cmd function.""" @@ -309,7 +317,7 @@ def test_run_shell_cmd_log(self): def test_run_cmd_negative_exit_code(self): """Test run_cmd function with command that has negative exit code.""" - # use of run_cmd is deprecated, so we need to allow it here + # use of run_cmd/run_cmd_qa is deprecated, so we need to allow it here self.allow_deprecated_behaviour() # define signal handler to call in case run_cmd takes too long @@ -777,6 +785,9 @@ def test_run_shell_cmd_trace_stdin(self): def test_run_cmd_qa(self): """Basic test for run_cmd_qa function.""" + # use of run_cmd_qa is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + cmd = "echo question; read x; echo $x" qa = {'question': 'answer'} with self.mocked_stdout_stderr(): @@ -812,7 +823,8 @@ def test_run_cmd_qa(self): error_pattern = "Max nohits 1 reached: end of output not-a-question-but-a-statement" self.assertErrorRegex(EasyBuildError, error_pattern, run_cmd_qa, cmd, qa, maxhits=1, trace=False) - (out, ec) = run_cmd_qa(cmd, qa, no_qa=["not-a-question-but-a-statement"], maxhits=1, trace=False) + with self.mocked_stdout_stderr(): + (out, ec) = run_cmd_qa(cmd, qa, no_qa=["not-a-question-but-a-statement"], maxhits=1, trace=False) self.assertEqual(out, "not-a-question-but-a-statement\nquestion\nanswer\n") self.assertEqual(ec, 0) @@ -901,6 +913,9 @@ def test_run_shell_cmd_qa(self): def test_run_cmd_qa_buffering(self): """Test whether run_cmd_qa uses unbuffered output.""" + # use of run_cmd_qa is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + # command that generates a lot of output before waiting for input # note: bug being fixed can be reproduced reliably using 1000, but not with too high values like 100000! cmd = 'for x in $(seq 1000); do echo "This is a number you can pick: $x"; done; ' @@ -964,6 +979,10 @@ def test_run_shell_cmd_qa_buffering(self): def test_run_cmd_qa_log_all(self): """Test run_cmd_qa with log_output enabled""" + + # use of run_cmd_qa is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + with self.mocked_stdout_stderr(): (out, ec) = run_cmd_qa("echo 'n: '; read n; seq 1 $n", {'n: ': '5'}, log_all=True) self.assertEqual(ec, 0) @@ -990,7 +1009,7 @@ def test_run_shell_cmd_qa_log(self): def test_run_cmd_qa_trace(self): """Test run_cmd under --trace""" - # use of run_cmd is deprecated, so we need to allow it here + # use of run_cmd/run_cmd_qa is deprecated, so we need to allow it here self.allow_deprecated_behaviour() # --trace is enabled by default @@ -1001,7 +1020,7 @@ def test_run_cmd_qa_trace(self): stderr = self.get_stderr() self.mock_stdout(False) self.mock_stderr(False) - self.assertEqual(stderr, '') + self.assertTrue(stderr.strip().startswith("WARNING: Deprecated functionality")) pattern = r"^ >> running interactive command:\n" pattern += r"\t\[started at: .*\]\n" pattern += r"\t\[working dir: .*\]\n" @@ -1054,6 +1073,10 @@ def test_run_shell_cmd_qa_trace(self): def test_run_cmd_qa_answers(self): """Test providing list of answers in run_cmd_qa.""" + + # use of run_cmd_qa is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + cmd = "echo question; read x; echo $x; " * 2 qa = {"question": ["answer1", "answer2"]} @@ -1197,7 +1220,12 @@ def test_run_shell_cmd_cache(self): def test_parse_log_error(self): """Test basic parse_log_for_error functionality.""" - errors = parse_log_for_error("error failed", True) + + # use of parse_log_for_error is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + + with self.mocked_stdout_stderr(): + errors = parse_log_for_error("error failed", True) self.assertEqual(len(errors), 1) def test_run_cmd_dry_run(self): @@ -1419,7 +1447,7 @@ def test_run_shell_cmd_stream(self): def test_run_cmd_async(self): """Test asynchronously running of a shell command via run_cmd + complete_cmd.""" - # use of run_cmd is deprecated, so we need to allow it here + # use of run_cmd/check_async_cmd/get_output_from_process is deprecated, so we need to allow it here self.allow_deprecated_behaviour() os.environ['TEST'] = 'test123' @@ -1453,13 +1481,15 @@ def test_run_cmd_async(self): # first check, only read first 12 output characters # (otherwise we'll be waiting until command is completed) - res = check_async_cmd(*cmd_info, output_read_size=12) + with self.mocked_stdout_stderr(): + res = check_async_cmd(*cmd_info, output_read_size=12) self.assertEqual(res, {'done': False, 'exit_code': None, 'output': 'sleeping...\n'}) # 2nd check with default output size (1024) gets full output # (keep checking until command is fully done) - while not res['done']: - res = check_async_cmd(*cmd_info, output=res['output']) + with self.mocked_stdout_stderr(): + while not res['done']: + res = check_async_cmd(*cmd_info, output=res['output']) self.assertEqual(res, {'done': True, 'exit_code': 0, 'output': 'sleeping...\ntest123\n'}) # check asynchronous running of failing command @@ -1468,14 +1498,16 @@ def test_run_cmd_async(self): cmd_info = run_cmd(error_test_cmd, asynchronous=True) time.sleep(1) error_pattern = 'cmd ".*" exited with exit code 123' - self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info) + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info) with self.mocked_stdout_stderr(): cmd_info = run_cmd(error_test_cmd, asynchronous=True) - res = check_async_cmd(*cmd_info, fail_on_error=False) + res = check_async_cmd(*cmd_info, fail_on_error=False) # keep checking until command is fully done - while not res['done']: - res = check_async_cmd(*cmd_info, fail_on_error=False, output=res['output']) + with self.mocked_stdout_stderr(): + while not res['done']: + res = check_async_cmd(*cmd_info, fail_on_error=False, output=res['output']) self.assertEqual(res, {'done': True, 'exit_code': 123, 'output': "FAIL!\n"}) # also test with a command that produces a lot of output, @@ -1498,10 +1530,11 @@ def test_run_cmd_async(self): ec = proc.poll() self.assertEqual(ec, None) - while ec is None: - time.sleep(1) - output += get_output_from_process(proc) - ec = proc.poll() + with self.mocked_stdout_stderr(): + while ec is None: + time.sleep(1) + output += get_output_from_process(proc) + ec = proc.poll() with self.mocked_stdout_stderr(): out, ec = complete_cmd(*cmd_info, simple=False, output=output) @@ -1514,8 +1547,9 @@ def test_run_cmd_async(self): cmd_info = run_cmd(verbose_test_cmd, asynchronous=True) error_pattern = r"Number of output bytes to read should be a positive integer value \(or zero\)" - self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info, output_read_size=-1) - self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info, output_read_size='foo') + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info, output_read_size=-1) + self.assertErrorRegex(EasyBuildError, error_pattern, check_async_cmd, *cmd_info, output_read_size='foo') # with output_read_size set to 0, no output is read yet, only status of command is checked with self.mocked_stdout_stderr(): @@ -1531,8 +1565,9 @@ def test_run_cmd_async(self): self.assertTrue(res['output'].startswith('start\n')) self.assertFalse(res['output'].endswith('\ndone\n')) # keep checking until command is complete - while not res['done']: - res = check_async_cmd(*cmd_info, output=res['output']) + with self.mocked_stdout_stderr(): + while not res['done']: + res = check_async_cmd(*cmd_info, output=res['output']) self.assertEqual(res['done'], True) self.assertEqual(res['exit_code'], 0) self.assertEqual(len(res['output']), 435661) @@ -1599,13 +1634,19 @@ def test_run_shell_cmd_async(self): self.assertTrue(res.output.endswith('\nfoo501000\ndone\n')) def test_check_log_for_errors(self): + """Test for check_log_for_errors""" + + # use of check_log_for_errors is deprecated, so we need to allow it here + self.allow_deprecated_behaviour() + fd, logfile = tempfile.mkstemp(suffix='.log', prefix='eb-test-') os.close(fd) - self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [42]) - self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [(42, IGNORE)]) - self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", "invalid-mode")]) - self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", IGNORE, "")]) + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [42]) + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [(42, IGNORE)]) + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", "invalid-mode")]) + self.assertErrorRegex(EasyBuildError, "Invalid input:", check_log_for_errors, "", [("42", IGNORE, "")]) input_text = "\n".join([ "OK", @@ -1620,20 +1661,24 @@ def test_check_log_for_errors(self): r"\tthe process crashed with 0" # String promoted to list - self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, - r"\b(error|crashed)\b") + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, + r"\b(error|crashed)\b") # List of string(s) - self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, - [r"\b(error|crashed)\b"]) + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, + [r"\b(error|crashed)\b"]) # List of tuple(s) - self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, - [(r"\b(error|crashed)\b", ERROR)]) + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, + [(r"\b(error|crashed)\b", ERROR)]) expected_msg = "Found 2 potential error(s) in command output:\n"\ "\terror found\n"\ "\tthe process crashed with 0" init_logging(logfile, silent=True) - check_log_for_errors(input_text, [(r"\b(error|crashed)\b", WARN)]) + with self.mocked_stdout_stderr(): + check_log_for_errors(input_text, [(r"\b(error|crashed)\b", WARN)]) stop_logging(logfile) self.assertIn(expected_msg, read_file(logfile)) @@ -1642,12 +1687,13 @@ def test_check_log_for_errors(self): r"\ttest failed" write_file(logfile, '') init_logging(logfile, silent=True) - self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, [ - r"\berror\b", - (r"\ballowed-test failed\b", IGNORE), - (r"(?i)\bCRASHED\b", WARN), - "fail" - ]) + with self.mocked_stdout_stderr(): + self.assertErrorRegex(EasyBuildError, expected_msg, check_log_for_errors, input_text, [ + r"\berror\b", + (r"\ballowed-test failed\b", IGNORE), + (r"(?i)\bCRASHED\b", WARN), + "fail" + ]) stop_logging(logfile) expected_msg = "Found 1 potential error(s) in command output:\n\tthe process crashed with 0" self.assertIn(expected_msg, read_file(logfile)) @@ -1657,7 +1703,7 @@ def test_run_cmd_with_hooks(self): Test running command with run_cmd with pre/post run_shell_cmd hooks in place. """ - # use of run_cmd is deprecated, so we need to allow it here + # use of run_cmd/run_cmd_qa is deprecated, so we need to allow it here self.allow_deprecated_behaviour() cwd = os.getcwd()