为什么“ go test -v”看不到GOPATH或GOPATH但“ go env”却看到?

The application works fine when I run it locally with: $ dev_appserver.py app.yaml

However, when I attempt to run tests, the ENV doesn't seem to be set.

$ go test -v

skincare.go:6:5: cannot find package "appengine" in any of:
    /usr/local/go/src/appengine (from $GOROOT)
    /Users/bryan/go/src/appengine (from $GOPATH)
skincare.go:7:5: cannot find package "appengine/datastore" in any of:
    /usr/local/go/src/appengine/datastore (from $GOROOT)
    /Users/bryan/go/src/appengine/datastore (from $GOPATH)
skincare.go:8:5: cannot find package "appengine/user" in any of:
    /usr/local/go/src/appengine/user (from $GOROOT)
    /Users/bryan/go/src/appengine/user (from $GOPATH)

$ go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

$GOPATH should not not contain the src part of the path. So instead of pointing to /Users/bryan/go/src/ it should point to /Users/bryan/go.

I suspect your tests are failing because you're invoking them directly with go test rather than using the App Engine SDK's test runner, goapp test, which will link you to the appengine package when it runs.

Go 1.11以上版本的模块支持使用一个临时环境变量GO111MODULE,可以将其设置为三个字符串值之一:off,on或auto(默认值)。如果GO111MODULE = off,那么go命令将永远不使用新的模块支持。相反,它在供应商目录和GOPATH中查找依赖关系。我们现在将此称为“ GOPATH模式”。如果GO111MODULE = on,则go命令需要使用模块,从不咨询GOPATH。我们将其称为命令可识别模块或在“模块可识别模式”下运行。如果GO111MODULE = auto或未设置,则go命令基于当前目录启用或禁用模块支持。仅当当前目录位于GOPATH / src之外且其本身包含go.mod文件或位于包含go的目录下时,才启用模块支持。