Skip to content

Resolves #4074 Add timestamp attribute testsuite element in xunit output - #4144

Merged
pekkaklarck merged 6 commits into
robotframework:masterfrom
rikerfi:xunit_timestamp
Nov 29, 2021
Merged

pekkaklarck merged 6 commits into
robotframework:masterfrom
rikerfi:xunit_timestamp

Conversation

@rikerfi

@rikerfi rikerfi commented Nov 13, 2021

Copy link
Copy Markdown
Contributor

Resolves issue #4074 by adding the timestamp attribute to testsuite element in xunit output. The timestamp is generated from the testsuite starttime which seems to be procedure in other tools as well. Furthermore, strong assumption is done that RF starttime format is always YYYYMMDD hh:mm:ss.mil. Starttime with empty string '' or None yields xunit timestamp attribute to empty value as well: timestamp="".

Valid RF starttime yields e.g. 2021-11-10T21:34:30.006000

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but a test for suite not having a start time is needed.

Comment thread src/robot/reporting/xunitwriter.py Outdated
isoformat = None
if stime:
isoformat = f'{stime[:4]}-{stime[4:6]}-{stime[6:8]}T{stime[9:22]}000'
return isoformat

@pekkaklarck pekkaklarck Nov 16, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if None is returned here? Will we get timestamp='None', timestamp='', not timestamp at all, or a crash? I'd prefer not having timestamp at all, but if xumit schema requires it then timestamp='' is probably best. Anyway, we need a test for this.

I'd also write this code like below to simplify it a bit:

if not stime:
    return None
return f'...'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return None yields timestamp="" currently. I made that part unit testing by hand, but will write the test as well. Also, I'll modify the routine more simply as proposed.

@rikerfi
rikerfi requested a review from pekkaklarck November 21, 2021 15:15

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is fine but tests are pretty complicated and there are some tests that don't seem to really test xunit outputs at ll. Please take a look at the individual comments and ping me on Slack if you need any help.

Comment thread atest/resources/atest_resource.robot Outdated
... stdout=${STDOUTFILE} stderr=${STDERRFILE} output_encoding=SYSTEM
... timeout=5min on_timeout=terminate
[Return] ${result}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this new keyword needed? Why isn't Run Tests or Run Rebot enough? If this is really needed by new tests, could it be in the same suite as those tests? This doesn't look too generic to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this keyword because of missing option(s) in between test execution and post-processing. Example of this kind of option is --starttime. Thus we need to execute test without processing the output. Then we need this new keyword as legacy Execute will set the execution environment causing the test output flushed. This is the rationale behind the new keyword. How generally this is needed? Probably not so much. I'll move it into the suite keywords.

Comment thread atest/robot/output/xunit.robot Outdated
Stderr Should Contain Command line option --xunitskipnoncritical has been deprecated and has no effect.

Nullish timestamp prerebotmodifier
Nullish Timestamp Should Be ${EMPTY}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit odd to pass ${EMPTY} as an argument when it could be just used in this keyword. The keyword should then be renamed, perhaps just adding Empty at its end is enough.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also a bit questionable is this test needed at all. There's a separate test using Rebot where the start time of the root suite is None "naturally". There may be no real need to have a separate tests where start time is removed otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-thinking this one as well. Not much added value and will keep tests more streamlined if I just remove it.

Comment thread atest/robot/output/xunit.robot Outdated
Remove Suite Status Element ${OUTFILE}
Execute On Existing Execution Environment
... ${INTERPRETER.rebot} --xUnit xunit.xml -l log.html ${OUTFILE} ${COMMON DEFAULTS}
Verify Xfile Timestamp ${EMPTY}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests seem to mainly validate that Rebot can parse output.xml files with missing information. I don't think it has anything to do with xunit files and it would probably be best to just remove these tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. These are more like a play around and learn the system. Will remove.

Comment thread atest/robot/output/xunit.robot Outdated
Run Tests Without Processing Output -l log.html ${PASS AND FAIL}
Execute On Existing Execution Environment
... ${INTERPRETER.rebot} ${OPTIONS WITH TIMES} ${OUTFILE} ${COMMON DEFAULTS}
Verify Xfile Timestamp ${XTIMESTAMP}

@pekkaklarck pekkaklarck Nov 24, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look fine but I don't understand the need to use the new Execute On Existing Execution Environment keyword. As far as I can the normal Run Rebot would work.

With the last test it probably would be possible to use also Run Tests, but then we needed to create the expected xunit timestamp based on suite start time ourselves. Something like this could possibly work:

Run Tests    --xunit xunit.xml    ${PASS AND FAIL}
Verify XUnit Timestamp    ${{datetime.datetime.strptime($SUITE.starttime, '%Y%m%d %H:%M:%S.%f').strftime('%Y-%m-%dT%H:%M:%S.%f')}}

Yeah, that timestamp conversion is quite complicated. With tests using Rebot specifying the start time using --starttime is a very good idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel Merge outputs with times and Rebot with start and end time are falling to very same test in the end. Removing the merge one.

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little test tuning could still be done. Especially the Execute On Existing Execution Environment keyword looks strange.

Comment thread atest/robot/output/xunit.robot Outdated
${XTIMESTAMP} 2021-12-15T12:11:10.456000
${ETIME} 20211215-12:13:14.789
${OPTIONS WITH TIMES}
... -x xunit.xml -l log.html --starttime ${STIME} --endtime ${ETIME}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most, if not all, of these variables are used in tests only once. Tests would probably be easier to understand if actual values were used directly.

Comment thread atest/robot/output/xunit.robot Outdated
[Arguments] ${pattern}
File Should Exist ${OUTDIR}/xunit.xml
${suite} = Get XUnit Node
Should match ${suite.attrib['timestamp']} ${pattern}

@pekkaklarck pekkaklarck Nov 29, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be Should Be Equal instead of Should Match. For consistence reasons and also otherwise it would be even better to use Element Attribute Should Be like in the keyword above.

Comment thread atest/robot/output/xunit.robot Outdated
${result} = Run Process @{executor} @{arguments}
... stdout=${STDOUTFILE} stderr=${STDERRFILE} output_encoding=SYSTEM
... timeout=5min on_timeout=terminate
[Return] ${result}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand the need for this special keyword. Why couldn't test just use Run Rebot?

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. New tests using Rebot could validate also other things than timestamps but I can fine tune these tests myself after merging this.

@pekkaklarck
pekkaklarck merged commit 6f59489 into robotframework:master Nov 29, 2021
@pekkaklarck

Copy link
Copy Markdown
Member

Rebot actually has a separate suite for xunit file. I'll move Rebot related tests there.

pekkaklarck added a commit that referenced this pull request Nov 29, 2021
@rikerfi
rikerfi deleted the xunit_timestamp branch November 30, 2021 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants