From a467c04d04695b7f61b530668736d84e6a3e1da8 Mon Sep 17 00:00:00 2001 From: Eric Graham Date: Mon, 1 May 2023 15:51:25 -0500 Subject: [PATCH] Clarify Failing Test Message; Search for Entire Log Line in caplog --- tests/pytests/unit/states/test_pip.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/pytests/unit/states/test_pip.py b/tests/pytests/unit/states/test_pip.py index 1b6d8afb364..7d93faa3eb8 100644 --- a/tests/pytests/unit/states/test_pip.py +++ b/tests/pytests/unit/states/test_pip.py @@ -53,22 +53,19 @@ def test_issue_64169(caplog): log=None # Regression will cause this function call to throw # an AttributeError ) - except AttributeError: + except AttributeError as exc: # Observed behavior in #64169 - assert False + pytest.fail( + 'Regression on #64169: pip_state.installed seems to be throwing an unexpected AttributeException: ' + f'{exc}' + ) except: # Something went wrong, but it isn't what's being tested for here. return # Take 64169 further and actually confirm that the exception from pip.list got logged. - exc_msg_present = False - for log_line in caplog.messages: - # The exception must be somewhere in the log, but may optionally not be on a line by itself. - if exception_message in log_line: - exc_msg_present = True - break - - assert exc_msg_present + assert 'Pre-caching of PIP packages during states.pip.installed failed by exception ' \ + f'from pip.list: {exception_message}' in caplog.messages # Confirm that the state continued to install the package as expected. # Only check the 'pkgs' parameter of pip.install