]> git.sur5r.net Git - u-boot/blobdiff - test/py/conftest.py
test/py: Make print statements python 3.x safe
[u-boot] / test / py / conftest.py
index 6e66a48c15fdad796150467da5d6589bcf5758fb..e591f5879dcb60ca26f0ecfd9555067bd162e18c 100644 (file)
@@ -1,7 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2015 Stephen Warren
 # Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-#
-# SPDX-License-Identifier: GPL-2.0
 
 # Implementation of pytest run-time hook functions. These are invoked by
 # pytest at certain points during operation, e.g. startup, for each executed
@@ -200,7 +199,7 @@ def pytest_configure(config):
         import u_boot_console_exec_attach
         console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
 
-re_ut_test_list = re.compile(r'_u_boot_list_2_(dm|env)_test_2_\1_test_(.*)\s*$')
+re_ut_test_list = re.compile(r'_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$')
 def generate_ut_subtest(metafunc, fixture_name):
     """Provide parametrization for a ut_subtest fixture.
 
@@ -344,6 +343,7 @@ tests_failed = []
 tests_xpassed = []
 tests_xfailed = []
 tests_skipped = []
+tests_warning = []
 tests_passed = []
 
 def pytest_itemcollected(item):
@@ -380,6 +380,11 @@ def cleanup():
     if log:
         with log.section('Status Report', 'status_report'):
             log.status_pass('%d passed' % len(tests_passed))
+            if tests_warning:
+                log.status_warning('%d passed with warning' % len(tests_warning))
+                for test in tests_warning:
+                    anchor = anchors.get(test, None)
+                    log.status_warning('... ' + test, anchor)
             if tests_skipped:
                 log.status_skipped('%d skipped' % len(tests_skipped))
                 for test in tests_skipped:
@@ -520,7 +525,9 @@ def pytest_runtest_protocol(item, nextitem):
         A list of pytest reports (test result data).
     """
 
+    log.get_and_reset_warning()
     reports = runtestprotocol(item, nextitem=nextitem)
+    was_warning = log.get_and_reset_warning()
 
     # In pytest 3, runtestprotocol() may not call pytest_runtest_setup() if
     # the test is skipped. That call is required to create the test's section
@@ -531,9 +538,14 @@ def pytest_runtest_protocol(item, nextitem):
         start_test_section(item)
 
     failure_cleanup = False
-    test_list = tests_passed
-    msg = 'OK'
-    msg_log = log.status_pass
+    if not was_warning:
+        test_list = tests_passed
+        msg = 'OK'
+        msg_log = log.status_pass
+    else:
+        test_list = tests_warning
+        msg = 'OK (with warning)'
+        msg_log = log.status_warning
     for report in reports:
         if report.outcome == 'failed':
             if hasattr(report, 'wasxfail'):
@@ -574,7 +586,7 @@ def pytest_runtest_protocol(item, nextitem):
         # is fixed, if this exception still exists, it will then be logged as
         # part of the test's stdout.
         import traceback
-        print 'Exception occurred while logging runtest status:'
+        print('Exception occurred while logging runtest status:')
         traceback.print_exc()
         # FIXME: Can we force a test failure here?