mbox series

[0/1] resulttool: Fix UnboundLocalError when missing ptests or image tests

Message ID 20260310125753.658173-1-miroslav.cernak@siemens.com
Headers show
Series resulttool: Fix UnboundLocalError when missing ptests or image tests | expand

Message

Miroslav Cernak March 10, 2026, 12:57 p.m. UTC
Hello maintainers,

This patch fixes an issue in resulttool's JUnit output generation that occurs when either ptest results or image test results are missing from the testresults.json file.

The problem was that variables for tracking test counts and metrics (image_errors, image_failures, ptest_errors, etc.) were being initialized
inside the test results loop. When certain test types were completely absent from the JSON, these variables would remain uninitialized,
causing UnboundLocalError exceptions when the code attempted to use them later.

The fix is simple: move the variable initialization outside the loop so they always have default values of 0, even when test sections are missing.

This patch also adds comprehensive test coverage for three scenarios:
- Empty testresults (e.g. missing testresults.json)
- Missing image tests (only ptest results present)
- Missing ptest results (only image tests present)

These edge cases can occur in various CI/build scenarios where not all test types are executed, and the tool should handle them gracefully
rather than failing with exceptions.

Please review and consider for inclusion.

Best regards,
Miroslav Cernak

Miroslav Cernak (1):
  resulttool: fix UnboundLocalError when missing test results The
    junit_tree function failed when either ptest or imagetest results
    were missing from testresults.json due to uninitialized variables.
    Move variable initialization outside the loop to ensure they always
    have default values.

 .../oeqa/selftest/cases/resulttooltests.py    | 109 ++++++++++++++++++
 scripts/lib/resulttool/junit.py               |   5 +-
 2 files changed, 112 insertions(+), 2 deletions(-)