summaryrefslogtreecommitdiff
path: root/tests/integration_tests
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-10-06 11:12:31 -0400
committerGitHub <noreply@github.com>2020-10-06 09:12:31 -0600
commitefa4d5be85c596c06cfd4c2613ab010ce54796e8 (patch)
tree7aefd8d4e0d9b70049b16a14637c5b7793f2deb8 /tests/integration_tests
parent5435205decf3c8582258d0782dc54aebdd154212 (diff)
downloadvyos-cloud-init-efa4d5be85c596c06cfd4c2613ab010ce54796e8.tar.gz
vyos-cloud-init-efa4d5be85c596c06cfd4c2613ab010ce54796e8.zip
integration_tests: improve cloud-init.log assertions (#593)
Diffstat (limited to 'tests/integration_tests')
-rw-r--r--tests/integration_tests/conftest.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py
index a170bfc9..37197ae3 100644
--- a/tests/integration_tests/conftest.py
+++ b/tests/integration_tests/conftest.py
@@ -104,3 +104,29 @@ def class_client(request, fixture_utils):
"""Provide a client that runs once per class."""
with _client(request, fixture_utils) as client:
yield client
+
+
+def pytest_assertrepr_compare(op, left, right):
+ """Custom integration test assertion explanations.
+
+ See
+ https://docs.pytest.org/en/stable/assert.html#defining-your-own-explanation-for-failed-assertions
+ for pytest's documentation.
+ """
+ if op == "not in" and isinstance(left, str) and isinstance(right, str):
+ # This stanza emits an improved assertion message if we're testing for
+ # the presence of a string within a cloud-init log: it will report only
+ # the specific lines containing the string (instead of the full log,
+ # the default behaviour).
+ potential_log_lines = right.splitlines()
+ first_line = potential_log_lines[0]
+ if "DEBUG" in first_line and "Cloud-init" in first_line:
+ # We are looking at a cloud-init log, so just pick out the relevant
+ # lines
+ found_lines = [
+ line for line in potential_log_lines if left in line
+ ]
+ return [
+ '"{}" not in cloud-init.log string; unexpectedly found on'
+ " these lines:".format(left)
+ ] + found_lines