Skip to content

Commit

Permalink
Fixed and simplified invocation of wbemcli in test_wbemcli.py
Browse files Browse the repository at this point in the history
Details:
- In test_wbemcli.py, the `wbemcli` command was invoked with `PYTHONPATH=.`
  which causes the `wbemcli` script from the working directory to be used
  and not the one generated by the Pip installer that wrappers that script.
  In certain situations this causes the testcases to fail because the
  wbemcli script in the working directory is not found by the wrapper wbemcli
  script.
  This was fixed by removing PYTHONPATH=. from the invocation.
  I cannot currrently reproduce the error situation, but the change
  seems correct in any case (because the wrapper script is supposed to be
  used).
- Simplified invocation of  the `wbemcli` command in `test_wbemcli.py` by
  no longer setting pipefail (the invocation does not use piping).
- Improved the assertion failure messages, for better diagnostics in case
  of failures.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Dec 10, 2017
1 parent 72c211e commit 42ec8c9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions testsuite/test_wbemcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def test(self): # pylint: disable=missing-docstring
# Disable python warnings for wbemcli call
# because some imports generate deprecated warnings
# that appear in std_err when nothing expected
bash_cmd = 'bash -c "set -o pipefail; PYTHONPATH=. ' \
'PYTHONWARNINGS= %s"' % cmd
bash_cmd = 'bash -c "PYTHONWARNINGS= %s"' % cmd

proc = Popen(bash_cmd, shell=True, stdout=PIPE, stderr=PIPE)
std_out, std_err = proc.communicate()
Expand All @@ -159,29 +158,30 @@ def test(self): # pylint: disable=missing-docstring

if test_params.expected_exitcode is not None:
self.assertEqual(exitcode, test_params.expected_exitcode,
('Test %s: Unexpected ExitCode Err. '
'Expected %s: cmd="%s": '
'exitcode %s: stderr=%s' %
("Test %s: Unexpected exit code "
"(expected %s, got %s) from command:\n"
"%s\n"
"stderr:\n"
"%s" %
(test_name, test_params.expected_exitcode,
cmd,
exitcode, std_err)))
exitcode, cmd, std_err)))

if test_params.expected_stderr is None:
if re.search('ImportWarning', std_err) is None:
self.assertEqual(std_err, "",
'Test %s stderr not empty as '
'Test %s: stderr not empty as '
'expected. Returned %s'
% (test_name, std_err))
else:
print('Ignored junk in stderr %s' % std_err)
self.assertEqual(std_err, "",
'Test %s stderr not empty as expected. '
'Test %s: stderr not empty as expected. '
'Returned %s'
% (test_name, std_err))
else:
for item in test_params.expected_stderr:
match_result = re.search(item, std_err)
self.assertNotEqual(match_result, None, 'Test %s, '
self.assertNotEqual(match_result, None, 'Test %s: '
'stderr did not match test '
'definition. Expected %s in %s' %
(test_name, item, std_err))
Expand All @@ -190,12 +190,12 @@ def test(self): # pylint: disable=missing-docstring
for item in test_params.expected_stdout:
match_result = re.search(item, std_out)
self.assertNotEqual(match_result, None,
'Test=%s, stdout did not match '
'Test=%s: stdout did not match '
'test definition. Expected %s in %s'
% (test_name, item, std_out))
else:
self.assertEqual(std_out, "",
'Test %s stdout not empty as expected. '
'Test %s: stdout not empty as expected. '
'Returned %s'
% (test_name, std_out))
return test
Expand Down

0 comments on commit 42ec8c9

Please sign in to comment.