onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.39k stars 660 forks source link

could not log in Eventually with fmt.Fprintf(GinkgoWriter) #1388

Open woodgear opened 7 months ago

woodgear commented 7 months ago
package books_test

import (
    "fmt"
    "testing"

    . "github.com/onsi/ginkgo/v2"
    . "github.com/onsi/gomega"
)

var _ = Describe("Books", func() {
    It("should be a novel", func() {
        fmt.Fprintf(GinkgoWriter, "here\n")
        Eventually(func(g Gomega) {
            fmt.Println("println here")
            fmt.Fprintf(GinkgoWriter, "in eventually here\n")
            g.Expect(true).To(BeFalse(), "sth wrong")
        }, "10m", "2s").Should(Succeed())
    })
})

func TestBooks(t *testing.T) {
    RegisterFailHandler(Fail)
    RunSpecs(t, "Books Suite")
}

the output is

=== RUN   TestBooks
Running Suite: Books Suite - /home/cong/sm/tmp/tgg
==================================================
Random Seed: 1713324181

Will run 1 of 1 specs
println here
println here
println here
println here
println here
println here

notice that "sth wrong" or "in eventually here" does not show out.

onsi commented 7 months ago

The GinkgoWriter output will only show when the test finally fails. You could try with ginkgo -v to see the output streamed immediately (though this only works when running in series i.e. not with ginkgo -p).

woodgear commented 7 months ago

i did use ginkgo -v, and it still not output streamed. 图片

woodgear commented 7 months ago

what i expect is it should print "sth wrong" each 2s.