Repository navigation
Test Metadata Feature - #5685
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for per-test-case metadata end-to-end (parsing → running model → result model → XML output → Rebot → log/report JS model + HTML rendering).
Changes:
- Parse
[Metadata]in test cases and store it on running/resultTestCasemodels. - Persist test metadata in output.xml (
<meta name="...">value</meta>) and read it back. - Expose test metadata in JS log model, update log.html template, and add acceptance tests.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| utest/reporting/test_jsmodelbuilders.py | Updates expected JS model structure to include metadata for tests. |
| src/robot/running/suiterunner.py | Passes parsed test metadata into the execution result test object. |
| src/robot/running/model.py | Extends running test model constructor to carry metadata. |
| src/robot/running/builder/transformers.py | Collects per-test metadata during parsing/model transformation. |
| src/robot/result/xmlelementhandlers.py | Allows <meta> children under <test> when building results from XML. |
| src/robot/result/model.py | Extends result test model constructor to accept metadata. |
| src/robot/reporting/jsmodelbuilders.py | Emits test metadata into the JS model used by logs/reports. |
| src/robot/parsing/lexer/settings.py | Enables Metadata setting within test case settings. |
| src/robot/output/xmllogger.py | Writes test metadata into output.xml as <meta> elements. |
| src/robot/model/testcase.py | Adds metadata to the data model and includes it in to_dict(). |
| src/robot/htmldata/rebot/testdata.js | Parses metadata from the JS model and shifts indices accordingly. |
| src/robot/htmldata/rebot/model.js | Stores parsed metadata on the JS Test object. |
| src/robot/htmldata/rebot/log.html | Renders test metadata rows in the log. |
| atest/testdata/output/testcase_metadata.robot | New test data exercising [Metadata] in test cases. |
| atest/robot/output/testcase_metadata.robot | New acceptance tests covering model, XML, Rebot, and log rendering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {{each metadata}} | ||
| <tr> | ||
| <th>{{html $value[0]}}:</th> | ||
| <td class="doc">{{html $value[1]}}</td> | ||
| </tr> | ||
| {{/each}} |
There was a problem hiding this comment.
This seems to be true and we also seem to have the same issue with existing suite metadata.
There was a problem hiding this comment.
Was it @febb0e so that also keys are escaped and using {{html ...}} is safe (and actually required to avoid double escaping)?
| data["doc"] = self.doc | ||
| if self.tags: | ||
| data["tags"] = tuple(self.tags) | ||
| if self.metadata: | ||
| data["metadata"] = self.metadata |
| tags: "Tags | Sequence[str]" = (), | ||
| timeout: "str | None" = None, | ||
| lineno: "int | None" = None, | ||
| metadata: "dict | None" = None, |
| return Tags(tags) | ||
|
|
||
| @setter | ||
| def metadata(self, metadata: "dict|None") -> Metadata: |
|
Makes #5495 obsolete |
|
I took a somewhat quick look at the changes and they look great! It's pretty cool how little changes were actually needed. I also looked at the AI review comments and agreed with most of them. Things to do before this can be merged:
After this has been merged, the functionality still needs to be documented. Could you @febb0e take a look at that as well? Probably better to open a separate PR for that. Overall this looks so good that I move the related issue back to RF 7.5 scope. This most likely won't make it to the first alpha/beta that I plan to release this week, but I see no problems getting this in before the final version. |
|
One thing that's missing is that XML and JSON schemas need to be updated. I can take care of that if needed. |
|
Hey @pekkaklarck |
|
Hey @pekkaklarck Thanks again for the review! I went through all of the AI comments and fixed the ones that turned out to be real issues:
One comment (the log.html escaping one) is a false positive in my opinion, the key and value are already escaped via the same html_escape/html_format that the suite metadata uses, so I left that as is. While working on this I found a handful of small bugs in the surrounding code that showed up when testing the feature end-to-end.
I did consider adding a Also let me know if you want anything split out or done differently! |
|
Thanks for the update! I'm back from holiday and will review this now. Hopefully we get this in soon and can then create RF 7.5 rc 1! Great that you found and fixed those issues surrounding the main logic. It's hard to remember to get all of such cases covered, and I'd be surprised if we didn't need to make some adjustments still in the subsequent releases. I agree |
pekkaklarck
left a comment
There was a problem hiding this comment.
Looks really good!
My comments seem to be only related to acceptance tests and they are mostly about style. Formatting metadata values definitely needs to be tested on acceptance test level, but it seems to be unit tested so the functionality ought to work fine.
I'm pretty sure there are some corner cases we have missed, but let's merge this now and fix possible problems afterwards. I can also fix the minor test issues myself at the same time as I experiment with this feature locally.
| @@ -0,0 +1,41 @@ | |||
| *** Settings *** | |||
| Resource atest_resource.robot | |||
| Suite Setup Run Tests --log log.html --report report.html output/testcase_metadata.robot | |||
There was a problem hiding this comment.
Could add validate output=True here to explicitly validate output.xml against the schema.
Schema validation can be enabled for all cases where output.xml is parsed with like atest/run.py -S. It slows execution a bit so it's not done by default, but explicitly enabling it where it makes sense is fine.
| Should Be Equal ${ticket.text} RF-9999 | ||
| ${html} = Get Element ${OUTFILE} .//test[@name="Test With Metadata"]/meta[@name="Html"] | ||
| Should Be Equal ${html.text} <b>value</b> & data | ||
| Element Should Not Exist ${OUTFILE} xpath=.//test[@name="Test Without Metadata"]/meta |
There was a problem hiding this comment.
We haven't tested other constructs in XML this way. We have just validated that information is available in the model after parsing XML, like the previous test does, and also validated that outputs match the schema. That said, I don't see real harm in validating XML also like this so probably we can leave this test as it is.
| Test Case Metadata Is Included In JSON Output | ||
| Copy Previous Outfile | ||
| Run Tests Without Processing Output -o output.json output/testcase_metadata.robot | ||
| Outputs Should Contain Same Data ${OUTFILE COPY} ${OUTDIR}/output.json ignore_timestamps=True |
There was a problem hiding this comment.
It would be good to explicitly validate that tests contains correct metadata also in this case. Validating that results contain same data regardless the output file format is probably a good idea as well, but that functionality may be buggy and ignore test metadata.
| Test With Metadata | ||
| [Metadata] Owner Team Robot | ||
| [Metadata] Ticket RF-9999 | ||
| [Metadata] Html <b>value</b> & data |
There was a problem hiding this comment.
Perhaps "Escaped" would be a better name than "HTML". The point here is that the value is escaped.
Related to the above, suite metadata values support formatting using Robot's own syntax (and the plan is to support Markdown in the future). There should thus be an entry like this as well:
[Metadata] Formatting Robot *rocks*!
and in HTML the value should be Robot <b>rocks</b>!.
| {{each metadata}} | ||
| <tr> | ||
| <th>{{html $value[0]}}:</th> | ||
| <td class="doc">{{html $value[1]}}</td> | ||
| </tr> | ||
| {{/each}} |
There was a problem hiding this comment.
Was it @febb0e so that also keys are escaped and using {{html ...}} is safe (and actually required to avoid double escaping)?
|
As I wrote in the review, this looks good enough to be merged, but I'll wait that test run finishes before that. If you @febb0e are online, you can look and possibly fix the small issues I commented while tests run, but I can also fix them myself after merging this. The next major task related to this is documentation. After that we can still think about |
|
Hey @pekkaklarck Next thing was to add documentation, this was something I already prepared and just adjusted to your review. And I also added the &{TEST METADATA} and Set Test Metadata implementation. |
Closes #4409
Overview
Add support for testcase metadata via the normal test setting syntax:
[Metadata] Name ValueThis metadata is now carried through execution, written to
output.xml, parsed back from XML, into the log.What changed
Metadata.running+result) now includesmetadataon test cases.<meta name="...">...</meta>under each<test>.<meta>entries.Compatibility
Tests
Added acceptance suite for the core flow:
output.xmlrebotprocessingNotes
This change is only about explicit
[Metadata]in test cases.It does not introduce custom bracket settings like
[Owner]or a new CLI filtering flag.Usage example