For trivial errors like a QEMU -bios or -kernel option not pointing at an existing file, the pytest output is extremely confusing. It prints a stack trace for every single test after QMPError("Received empty response") is raised and the stderr text explaining that the file is missing is easily overlooked. Improve this by just existing right away once a strategy transition fails and print the standard error if any as part of the exit message. This looks a bit cumbersome, because the capsys fixture can't be used with a session-scoped fixture, see the still open pytest issue[1] for details. [1]: https://github.com/pytest-dev/pytest/issues/2704 Suggested-by: Bastian Krause <bst@xxxxxxxxxxxxxx> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- conftest.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/conftest.py b/conftest.py index 56d4b512a912..5639b7e22ebd 100644 --- a/conftest.py +++ b/conftest.py @@ -3,15 +3,26 @@ import os import argparse from test.py import helper +def transition_to_barebox(request, strategy): + try: + strategy.transition('barebox') + except Exception as e: + # If a normal strategy transition fails, there's no point in + # continuing the test. Let's print stderr and exit. + capmanager = request.config.pluginmanager.getplugin("capturemanager") + with capmanager.global_and_fixture_disabled(): + _, stderr = capmanager.read_global_capture() + pytest.exit(f"{type(e).__name__}(\"{e}\"). Standard error:\n{stderr}", + returncode=3) @pytest.fixture(scope='function') -def barebox(strategy, target): - strategy.transition('barebox') +def barebox(request, strategy, target): + transition_to_barebox(request, strategy) return target.get_driver('BareboxDriver') @pytest.fixture(scope="session") -def barebox_config(strategy, target): - strategy.transition('barebox') +def barebox_config(request, strategy, target): + transition_to_barebox(request, strategy) command = target.get_driver("BareboxDriver") return helper.get_config(command) -- 2.39.2