Repository navigation
Resolves #4074 Add timestamp attribute testsuite element in xunit output - #4144
Conversation
pekkaklarck
left a comment
There was a problem hiding this comment.
Looks good but a test for suite not having a start time is needed.
| isoformat = None | ||
| if stime: | ||
| isoformat = f'{stime[:4]}-{stime[4:6]}-{stime[6:8]}T{stime[9:22]}000' | ||
| return isoformat |
There was a problem hiding this comment.
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'...'
There was a problem hiding this comment.
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.
pekkaklarck
left a comment
There was a problem hiding this comment.
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.
| ... stdout=${STDOUTFILE} stderr=${STDERRFILE} output_encoding=SYSTEM | ||
| ... timeout=5min on_timeout=terminate | ||
| [Return] ${result} | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| Stderr Should Contain Command line option --xunitskipnoncritical has been deprecated and has no effect. | ||
|
|
||
| Nullish timestamp prerebotmodifier | ||
| Nullish Timestamp Should Be ${EMPTY} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Re-thinking this one as well. Not much added value and will keep tests more streamlined if I just remove it.
| 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} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
True. These are more like a play around and learn the system. Will remove.
| 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} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Little test tuning could still be done. Especially the Execute On Existing Execution Environment keyword looks strange.
| ${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} |
There was a problem hiding this comment.
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.
| [Arguments] ${pattern} | ||
| File Should Exist ${OUTDIR}/xunit.xml | ||
| ${suite} = Get XUnit Node | ||
| Should match ${suite.attrib['timestamp']} ${pattern} |
There was a problem hiding this comment.
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.
| ${result} = Run Process @{executor} @{arguments} | ||
| ... stdout=${STDOUTFILE} stderr=${STDERRFILE} output_encoding=SYSTEM | ||
| ... timeout=5min on_timeout=terminate | ||
| [Return] ${result} |
There was a problem hiding this comment.
I still don't understand the need for this special keyword. Why couldn't test just use Run Rebot?
pekkaklarck
left a comment
There was a problem hiding this comment.
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.
|
Rebot actually has a separate suite for xunit file. I'll move Rebot related tests there. |
Resolves issue #4074 by adding the timestamp attribute to testsuite element in xunit output. The timestamp is generated from the testsuite
starttimewhich seems to be procedure in other tools as well. Furthermore, strong assumption is done that RF starttime format is alwaysYYYYMMDD hh:mm:ss.mil. Starttime with empty string''orNoneyields xunit timestamp attribute to empty value as well:timestamp="".Valid RF starttime yields e.g.
2021-11-10T21:34:30.006000