Skip to content

[FIX] odoo_test_xmlrunner: attribute class-level errors to the right file - #3688

Open
yajo wants to merge 1 commit into
OCA:18.0from
moduon:18.0-odoo_test_xmlrunner-fix-junit-wrong-file
Open

[FIX] odoo_test_xmlrunner: attribute class-level errors to the right file#3688
yajo wants to merge 1 commit into
OCA:18.0from
moduon:18.0-odoo_test_xmlrunner-fix-junit-wrong-file

Conversation

@yajo

@yajo yajo commented Jul 30, 2026

Copy link
Copy Markdown
Member

Bug

When a setUpClass or tearDownClass fails, unittest creates an _ErrorHolder. Because xmlrunner.result._XMLTestResult.startTest is never called for these holders, self.filename keeps the value from the previous test. The JUnit report then attributes the failure to the wrong source file and leaves classname empty.

This was visible in the failing pipeline: https://gitlab.com/moduon/ataraxia/buffet-odoo/-/pipelines/2714813530/test_report?job_name=unittest%3A%20%5B19%5D

Fix

Parse the _ErrorHolder description (setUpClass/tearDownClass (module.ClassName)), use inspect to locate the real test class, and patch the stored _TestInfo in addError/addFailure so the generated XML points to the correct file and line.

A regression test is included.

Forward-port: #3689

Assisted-by: OpenCode + kimi-k2.7-code

@yajo

yajo commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

To help understand better the motivation of the fix, check out this visual representation of a buggy junit xml in Gitlab UI:

image

As you see, a failure in the setUpClass() of one module reports wrong error line (that belongs to another, unrelated, module).

@yajo
yajo force-pushed the 18.0-odoo_test_xmlrunner-fix-junit-wrong-file branch 2 times, most recently from be624f1 to 3e279ce Compare July 30, 2026 08:16
…file

When setUpClass or tearDownClass fails, unittest creates an _ErrorHolder

without running _XMLTestResult.startTest, so xmlrunner kept the source file of the previous test in self.filename. This made the JUnit report assign the failure to an unrelated module and left classname empty.

Resolve the real test class from the _ErrorHolder description (setUpClass/tearDownClass (module.ClassName)), look up its source file and line with inspect, and patch the stored test info in addError/addFailure before the report is generated. Include a regression test that reproduces the wrong-file issue and verifies the fix.

Assisted-by: OpenCode + kimi-k2.7-code
@yajo
yajo force-pushed the 18.0-odoo_test_xmlrunner-fix-junit-wrong-file branch from 3e279ce to be2bb9b Compare July 30, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:odoo_test_xmlrunner Module odoo_test_xmlrunner series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants