ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

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

Open woodgear opened this issue 10 months ago • 3 comments

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.

woodgear avatar Apr 17 '24 03:04 woodgear

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).

onsi avatar Apr 17 '24 03:04 onsi

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

woodgear avatar Apr 17 '24 04:04 woodgear

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

woodgear avatar Apr 17 '24 04:04 woodgear