Skip to content

testing: _test package runs init() in the containing folder  #58823

@bep

Description

@bep

I'm having problems finding good documentation about the expected behaviour of the _test package, but as I was bitten/surprised by this, it should warrant at least a searchable issue.

See the project and failing test in https://github.com/bep/gotestpackageinit/blob/main/pkga/int_test.go#L1

The test fails because the init() func in pkga panics (which is a little constructed, I agree).

My understanding is that pkga_test would be compiled as a separate package and that I could only access pkga's exported identifiers and only with an explicit import of that package.

In my case I had a great and working integration test of a feature that failed mysteriously in the production binary because the init() was never called.

gohugoio/hugo#10774

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions