suite: fix panic if a WithStats suite skips a test early#1723
suite: fix panic if a WithStats suite skips a test early#1723FGasper wants to merge 2 commits intostretchr:masterfrom
Conversation
…eTest. This fixes issue stretchr#1722.
|
While it works, I would have done differently to focus the change on the small portion of code that causes the issues. Here is the code that fails func (s SuiteInformation) end(testName string, passed bool) {
s.TestStats[testName].End = time.Now()
s.TestStats[testName].Passed = passed
}Your PR is about avoiding to call I would like to suggest limiting the change in your PR to this func (s SuiteInformation) end(testName string, passed bool) {
if _, started := s.TestStats[testName]; !started {
return
}
s.TestStats[testName].End = time.Now()
s.TestStats[testName].Passed = passed
}The test you added is good. |
|
@ccoVeille I myself think it’s better, if It’s not something I feel strongly about, though, so I’ll make the change you requested. |
|
@ccoVeille Altered accordingly, with a small tweak to reduce repetition. |
ccoVeille
left a comment
There was a problem hiding this comment.
@ccoVeille I myself think it’s better, if
start()was never called, to avoid callingend(); thus, I’d rather the fix be as I have it.
I understand your point, thanks for considering my fix.
Good idea with that tweak
|
@FGasper Could you rebase your branch and resolve the conflict? |
Summary
This fixes issue #1722.
Changes
Prevent stats.end() if stats.start() never ran.
Motivation
Allow skipping a test in a setup/before hook. See issue #1722 for an example.
Related issues
Closes #1722