dongzhuo7291
dongzhuo7291
采纳率100%
2017-11-28 17:17

Go测试失败,显示“无法加载软件包构建约束,排除了所有Go文件”

已采纳

当我运行这个命令时:

go test -tags integration $(go list ./... | grep -v /vendor/)

go测试失败,因为有些软件包的所有测试都标有:// +build !integration

can't load package: build constraints exclude all Go files

在这种情况下,有没有一种方法可以让 go test 忽略这些包?谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongyigua4468 dongyigua4468 4年前

    You will only get that error if all the files in the package are excluded by your build constraints, not just the test files. If that's what you want, just add a single package file with no code and the package will still be able to be loaded. For example, many packages put their package level docs in a separate file, which you could use to always have a valid package:

    // Package foo does foo
    package foo
    
    点赞 评论 复制链接分享

相关推荐