mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Bastian Krause <bst@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] test: directly exit when barebox state transition fails
Date: Thu, 22 Aug 2024 21:17:14 +0200	[thread overview]
Message-ID: <20240822191714.3768641-1-a.fatoum@pengutronix.de> (raw)

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@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 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




             reply	other threads:[~2024-08-22 19:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 19:17 Ahmad Fatoum [this message]
2024-08-23  8:04 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240822191714.3768641-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=bst@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox