[PATCH 2/4] tests/functional: avoid duplicate messages on failures

Daniel P. Berrangé posted 4 patches 1 day, 11 hours ago
Maintainers: Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
[PATCH 2/4] tests/functional: avoid duplicate messages on failures
Posted by Daniel P. Berrangé 1 day, 11 hours ago
In some scenarios the same tests is mentioned in both the
'res.results.errors' and 'res.results.failures' array returned
by unittest.main(). This was seen when the 'tearDown' method
raised an exception.

In such a case, we printed out the same information about where
to find a log file twice for each test. Track which tests we
have already reported on, to avoid the duplication.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/testcase.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index fbeb171058..82a7724404 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -251,13 +251,14 @@ def main():
                                    test_output_log = pycotap.LogMode.LogToError)
         res = unittest.main(module = None, testRunner = tr, exit = False,
                             argv=[sys.argv[0], path] + sys.argv[1:])
+        failed = {}
         for (test, message) in res.result.errors + res.result.failures:
-
-            if hasattr(test, "log_filename"):
+            if hasattr(test, "log_filename") and not test.id() in failed:
                 print('More information on ' + test.id() + ' could be found here:'
                       '\n %s' % test.log_filename, file=sys.stderr)
                 if hasattr(test, 'console_log_name'):
                     print(' %s' % test.console_log_name, file=sys.stderr)
+                failed[test.id()] = True
         sys.exit(not res.result.wasSuccessful())
 
 
-- 
2.50.1


Re: [PATCH 2/4] tests/functional: avoid duplicate messages on failures
Posted by Thomas Huth 14 hours ago
On 08/09/2025 15.57, Daniel P. Berrangé wrote:
> In some scenarios the same tests is mentioned in both the
> 'res.results.errors' and 'res.results.failures' array returned
> by unittest.main(). This was seen when the 'tearDown' method
> raised an exception.
> 
> In such a case, we printed out the same information about where
> to find a log file twice for each test. Track which tests we
> have already reported on, to avoid the duplication.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/qemu_test/testcase.py | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index fbeb171058..82a7724404 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -251,13 +251,14 @@ def main():
>                                      test_output_log = pycotap.LogMode.LogToError)
>           res = unittest.main(module = None, testRunner = tr, exit = False,
>                               argv=[sys.argv[0], path] + sys.argv[1:])
> +        failed = {}
>           for (test, message) in res.result.errors + res.result.failures:
> -
> -            if hasattr(test, "log_filename"):
> +            if hasattr(test, "log_filename") and not test.id() in failed:
>                   print('More information on ' + test.id() + ' could be found here:'
>                         '\n %s' % test.log_filename, file=sys.stderr)
>                   if hasattr(test, 'console_log_name'):
>                       print(' %s' % test.console_log_name, file=sys.stderr)
> +                failed[test.id()] = True
>           sys.exit(not res.result.wasSuccessful())

Reviewed-by: Thomas Huth <thuth@redhat.com>