From b0a928a15d7825c08f3be1a3ec5c4bcd8b465fd8 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Mon, 17 Oct 2016 17:25:52 -0600 Subject: test/py: ensure a log section exists for skipped tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In pytest 3, runtestprotocol() may not call pytest_runtest_setup() if the test is skipped. That call is required to create a section for the test in the log file. If this is skipped, the call to log.end_section() at the tail of pytest_runtest_protocol() will throw an exception. This patch ensures that a log section always exists, both to avoid the exception and to ensure that a consistently structured log file is always created. Cc: Stefan Brüns Reported-by: Stefan Brüns Signed-off-by: Stephen Warren Tested-by: Tom Rini --- test/py/conftest.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 5b3a92316b..1f15e3e33d 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -431,6 +431,9 @@ def setup_buildconfigspec(item): if not ubconfig.buildconfig.get('config_' + option.lower(), None): pytest.skip('.config feature not enabled') +def start_test_section(item): + anchors[item.name] = log.start_section(item.name) + def pytest_runtest_setup(item): """pytest hook: Configure (set up) a test item. @@ -444,7 +447,7 @@ def pytest_runtest_setup(item): Nothing. """ - anchors[item.name] = log.start_section(item.name) + start_test_section(item) setup_boardspec(item) setup_buildconfigspec(item) @@ -464,6 +467,14 @@ def pytest_runtest_protocol(item, nextitem): reports = runtestprotocol(item, nextitem=nextitem) + # 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 + # in the log file. The call to log.end_section() requires that the log + # contain a section for this test. Create a section for the test if it + # doesn't already exist. + if not item.name in anchors: + start_test_section(item) + failure_cleanup = False test_list = tests_passed msg = 'OK' -- cgit v1.2.3