Skip to content

Unable to use require within EventuallyWith #89

@boekkooi-impossiblecloud

Description

Describe the bug
Good day,

Currently I'm trying to migrate a project to go-openapi/testify and it seems to work well (thank you!).
I did run into one issue and that is that I'm unable to use (for example) require.Error inside assert.EventuallyWith as this always results in a condition never satisfied.
It looks like require.Error calls CollectT.FailNow which cancels the context causing failFunc(ctx.Err().Error()) to be called.

I'm not sure if this expected behavior or not. Could you please advice?

Thanks in advance and have a great day!

Steps to Reproduce

func TestExample(t *testing.T) {
	ctx, ctxCancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
	t.Cleanup(ctxCancel)

	assert.EventuallyWith(t, func(collect *assert.CollectT) {
		require.Error(collect, ctx.Err())
	}, time.Second, time.Millisecond)
}

Expected behavior

=== RUN   TestExample
--- PASS: TestExample (0.01s)
PASS

Actual behavior

=== RUN   TestExample
    condition.go:480: context canceled
    testing.go:110: 
        	Error Trace:	/home/warnar/.asdf/installs/golang/1.26.2/go/src/runtime/asm_amd64.s:1771
        	Error:      	condition never satisfied
        	Test:       	TestExample
--- FAIL: TestExample (0.00s)

FAIL

Environment

GOVERSION='go1.26.2'

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions