Skip to content

Commit 50a0437

Browse files
committed
Add pytest hook to update test report
1 parent dc0aeee commit 50a0437

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/conftest.py

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from kubernetes.config.kube_config import KUBE_CONFIG_DEFAULT_LOCATION
77
from settings import DEFAULT_IMAGE, DEFAULT_PULL_POLICY, DEFAULT_IC_TYPE, DEFAULT_SERVICE, DEFAULT_DEPLOYMENT_TYPE
8+
from suite.resources_utils import get_first_pod_name
89

910

1011
def pytest_addoption(parser) -> None:
@@ -54,3 +55,26 @@ def pytest_collection_modifyitems(config, items) -> None:
5455
for item in items:
5556
if "skip_for_nginx_oss" in item.keywords:
5657
item.add_marker(skip_for_nginx_oss)
58+
59+
60+
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
61+
def pytest_runtest_makereport(item) -> None:
62+
"""
63+
Print out IC Pod logs on test failure.
64+
65+
Only look at actual failing test calls, not setup/teardown
66+
67+
:param item:
68+
:return:
69+
"""
70+
# execute all other hooks to obtain the report object
71+
outcome = yield
72+
rep = outcome.get_result()
73+
74+
# we only look at actual failing test calls, not setup/teardown
75+
if rep.when == "call" and rep.failed:
76+
pod_namespace = item.funcargs['ingress_controller_prerequisites'].namespace
77+
pod_name = get_first_pod_name(item.funcargs['kube_apis'].v1, pod_namespace)
78+
print("===================== IC Logs Start =====================")
79+
print(item.funcargs['kube_apis'].v1.read_namespaced_pod_log(pod_name, pod_namespace))
80+
print("===================== IC Logs End =====================")

0 commit comments

Comments
 (0)