如何修复“PT006 @pytest.mark.parametrize 中的错误名称类型,预期元组”?

And*_*ski 6 python pytest python-3.x flake8

当我运行 flake8 时,出现以下错误:

./test_sample.py:4:2: PT006 wrong name(s) type in @pytest.mark.parametrize, expected tuple
Run Code Online (Sandbox Code Playgroud)

这是我的代码

import pytest


@pytest.mark.parametrize('foo,bar', [(1, 1), (2, 2)])
def test_foo(foo, bar):
    assert foo == bar
Run Code Online (Sandbox Code Playgroud)

pip freeze | egrep flake8:

flake8==3.8.4
flake8-plugin-utils==1.3.1
flake8-pytest-style==1.3.0
Run Code Online (Sandbox Code Playgroud)

我该如何修复该错误?

And*_*ski 10

此错误是由 生成的flake8-pytest-style。请参阅https://github.com/m-burst/flake8-pytest-style/blob/master/docs/rules/PT006.md

您有两个选择:

  • 'foo,bar'用。。。来代替('foo', 'bar')
    import pytest
    
    
    @pytest.mark.parametrize(('foo', 'bar'), [(1, 1), (2, 2)])
    def test_foo(foo, bar):
        assert foo == bar
    
    Run Code Online (Sandbox Code Playgroud)
  • pytest-parametrize-names-type通过将包含以下内容的文件添加.flake8到项目的根目录 来更改配置选项:
    [flake8]
    pytest-parametrize-names-type = csv
    
    Run Code Online (Sandbox Code Playgroud)