Running tests per package with Go module

72 views
Skip to first unread message

Dr Waryaa

unread,
Aug 20, 2019, 9:27:48 AM8/20/19
to golang-nuts
Hi,
I have a Go module which looks as follows:

go.mod
go.sum
     |
    ----- pkg1
    |
    -----pkg2

The module is called mydomain.com/mypkg

I'm trying to run the tests for pkg1 by calling

go test ./pkg1/...

My problem is that pkg1 imports mydomain.com/mypkg/pkg2 and that running the tests this way seems to mean that the go.mod is ignored and mydomain.com/mypkg/pkg2 is expected to be found in the GOPATH instead.

I suspect I could run

go test ...

but I would prefer running them one package at a time which was easy enough when using the GOPATH. Can I still do that with modules without having to install the package into $GOPATH/src/mydomain.com/mypkg ?

Cheers,
Chris

Jacques Supcik

unread,
Aug 20, 2019, 3:43:51 PM8/20/19
to golang-nuts
Hello Chris,

I made a small project with the same structure as yours to reproduce the problem : https://github.com/supcik/rtppwgm

But in my project, everything works as expected :

» go test -count=1 ./...
ok      demo/pkg1       0.006s
ok      demo/pkg2       0.006s

» go test -count=1 ./pkg1/...
ok      demo/pkg1       0.006s

» go test -count=1 ./pkg2/...
ok      demo/pkg2       0.005s

Can you make a similar project that exposes your issue ?

Cheers,

-- Jacques

Marcin Romaszewicz

unread,
Aug 20, 2019, 4:16:01 PM8/20/19
to Jacques Supcik, golang-nuts
It could fail if you're under $GOPATH and GO111MODULE=auto, since inside the GOPATH, auto=off

-- Marcin


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/22e3a0fc-ed57-4b53-9ad5-faefab58c800%40googlegroups.com.

Dr Waryaa

unread,
Aug 20, 2019, 9:44:17 PM8/20/19
to golang-nuts
Hi Jacques,
Thanks for trying that. I found out that I was on a wild goose chase. As it turns out, it was code that my TestMain
called which had a hard-coded reference looking for the GOPATH.

Cheers,
Chris
Reply all
Reply to author
Forward
0 new messages