Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AfterTest execution on FailNow or BreakNow #30

Closed
ReneHabermann opened this issue Mar 19, 2020 · 2 comments · Fixed by #32
Closed

AfterTest execution on FailNow or BreakNow #30

ReneHabermann opened this issue Mar 19, 2020 · 2 comments · Fixed by #32
Assignees

Comments

@ReneHabermann
Copy link

Hello again :)

I'd like to utilize AfterTest to prepare Attachments for the report. For example, i want to include container logs so that i can understand what failed. This only makes sense once the test is finished and it should be done in any case, so AfterTest is conceptionally the ideal place for it. My understanding of AfterTest is based on other test frameworks like junit, where it is always executed, especially to free resources allocated in a BeforeTest.

However, it seems to me that AfterTest is not executed if a FailNow or BreakNow was called. I tried putting AfterTest in the end of the method, in the beginning and deferred. Only with the defer call it executed, but then the same test appeared twice in the report (i assume this is because the test is already reported, but after test is executed afterwards and reports again with a slightly longer runtime):
Bildschirmfoto von 2020-03-19 09-19-52

So is there a right way to call AfterTest to achieve the common behaviour, or is this just not possible right now?

Code to reproduce:

package aa

import (
  "errors"
  . "github.com/dailymotion/allure-go"
  "log"
  "testing"
)

func Test_foo(t *testing.T) {
  Test(t,
    Description("actual test"),
    Action(func() {
      Step(
        Description("Test step 1"),
        Action(func() { BreakNow(errors.New("this breaks now")) }))
    }))

  AfterTest(t,
    Description("teardown"),
    Action(func() {
      Step(
        Description("Teardown step 1"),
        Action(func() {
          log.Println("i will never execute")
          AddAttachment("attach", TextPlain, []byte("hello my log"))
        }))
    }))
}
@ubermensch01 ubermensch01 self-assigned this Mar 30, 2020
@ubermensch01
Copy link
Collaborator

Hi @ReneHabermann,

My apologies for the delay.
You are correct, at the moment test terminates after allure.FailNow or allure.BreakNow is called.
Using deferred statement would be the recommended approach , we'll work on fixing the report to not create duplicate test records.

ubermensch01 pushed a commit that referenced this issue May 28, 2020
Signed-off-by: Stanislav Fedii <stanislav.fedii@gmail.coml>
@ubermensch01
Copy link
Collaborator

Hi @ReneHabermann,

Again, my apologies for taking forever to resolve this. I created a PR with a fix for the issue and will merge it shortly. Please let me know if that will resolve your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants