
From: Simon Glass <sjg@chromium.org> It is quite tricky to debug problems in the test.py code itself, as when something goes wrong the exception failure is caught and reported as a test failure. Add a -E option to simplify debugging. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/conftest.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 4460e5a3af2..7ac777fea7f 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -87,6 +87,9 @@ def pytest_addoption(parser): help='Compile U-Boot before running tests') parser.addoption('--buildman', default=False, action='store_true', help='Use buildman to build U-Boot (assuming --build is given)') + parser.addoption( + '-E', '--allow-exceptions', '-E', default=False, action='store_true', + help='Avoid catching exceptions with test failures') parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') @@ -336,6 +339,7 @@ def pytest_configure(config): ubconfig.connection_ok = True ubconfig.timing = config.getoption('timing') ubconfig.role = config.getoption('role') + ubconfig.allow_exceptions = config.getoption('allow_exceptions') env_vars = ( 'board_type', @@ -507,6 +511,9 @@ def ubman(request): if not ubconfig.connection_ok: pytest.skip('Cannot get target connection') return None + if ubman_fix.config.allow_exceptions: + ubman_fix.ensure_spawned() + return ubman_fix try: ubman_fix.ensure_spawned() except OSError as err: @@ -880,20 +887,23 @@ def pytest_runtest_protocol(item, nextitem): test_list.append(item.name) tests_not_run.remove(item.name) - try: + if ubman_fix.config.allow_exceptions: msg_log(msg) - except: - # If something went wrong with logging, it's better to let the test - # process continue, which may report other exceptions that triggered - # the logging issue (e.g. ubman_fix.log wasn't created). Hence, just - # squash the exception. If the test setup failed due to e.g. syntax - # error somewhere else, this won't be seen. However, once that issue - # 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:') - traceback.print_exc() - # FIXME: Can we force a test failure here? + else: + try: + msg_log(msg) + except: + # If something went wrong with logging, it's better to let the test + # process continue, which may report other exceptions that triggered + # the logging issue (e.g. ubman_fix.log wasn't created). Hence, just + # squash the exception. If the test setup failed due to e.g. syntax + # error somewhere else, this won't be seen. However, once that issue + # 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:') + traceback.print_exc() + # FIXME: Can we force a test failure here? log.end_section(item.name) -- 2.43.0 base-commit: 290829cc0d20dc4da5a8dfa43b94adcf368bc1b1 branch: labf