mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] test: directly exit when barebox state transition fails
@ 2024-08-22 19:17 Ahmad Fatoum
  2024-08-23  8:04 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-08-22 19:17 UTC (permalink / raw)
  To: barebox; +Cc: Bastian Krause, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] test: directly exit when barebox state transition fails
  2024-08-22 19:17 [PATCH] test: directly exit when barebox state transition fails Ahmad Fatoum
@ 2024-08-23  8:04 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-08-23  8:04 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: Bastian Krause


On Thu, 22 Aug 2024 21:17:14 +0200, Ahmad Fatoum wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] test: directly exit when barebox state transition fails
      https://git.pengutronix.de/cgit/barebox/commit/?id=acc33c6ca05e (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-23  8:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-22 19:17 [PATCH] test: directly exit when barebox state transition fails Ahmad Fatoum
2024-08-23  8:04 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox