gpt4 book ai didi

去测试标志: flag provided but not defined

转载 作者:IT老高 更新时间:2023-10-28 13:03:57 26 4
gpt4 key购买 nike

您好,我在 go 中测试时使用了一个标志:
file_test.govar ip = flag.String("ip", "noip", "test")

我只在一个测试文件中使用它。仅测试一个测试文件时它工作正常,但是当我运行时:go test ./... -ip 127.0.0.1 alle of the other test file say: flag provided but not defined.

你见过吗?

问候

最佳答案

flag.Parse() 在你的标志被定义之前被调用。

您必须确保所有标志定义发生在调用 flag.Parse() 之前,通常通过在 init() 函数中定义所有标志。

关于去测试标志: flag provided but not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29699982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com