[英]Potentially unused parameter in go when using testify's suite package
I want to execute subtests using the testify/suite
package .我想使用 testify testify/suite
package执行子测试。
I am declaring my Unit suite as follows我声明我的单元套件如下
type UnitSuite struct {
suite.Suite
}
func TestUnitSuite(t *testing.T) {
suite.Run(t, &UnitSuite{})
}
and here is my subtest这是我的子测试
func (us *UnitSuite) ΤestSomething() {
for i := range testVars {
i := i
us.T().Run(testVars[i].name, func(t *testing.T) {
...
Ι am getting the following linting warning for func(t *testing.T)
我收到以下关于func(t *testing.T)
的 linting 警告
potentially unused parameter: 't'unusedparams
When trying to substitute with the testing suite's function T()
that is supposes to retrieve the testing
context当尝试用测试套件的 function T()
替换时,它应该检索testing
上下文
us.T().Run(testVars[i].name, func(us.T()) {
I get this error in func(us.T())
<-- errors out我在func(us.T())
<--错误中得到这个错误
missing ',' in parameter listsyntax
What is the way to go about this that does not produce neither errors nor linting warnings? go 的方法是什么,既不会产生错误也不会产生 linting 警告?
If you want to declare an unused parameter (usually to satisfy an interface or other requirements), you can name it a single underscore.如果要声明未使用的参数(通常是为了满足接口或其他要求),可以将其命名为单个下划线。 For example:例如:
Run(name, func(_ *testing.T) {})
Note that you cannot put a value in function declaration, so func(us.T()) {
is always wrong.请注意,您不能在 function 声明中输入值,因此func(us.T()) {
总是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.