【问题标题】:How to fix "PT006 wrong name(s) type in @pytest.mark.parametrize, expected tuple"?如何修复“@pytest.mark.parametrize,预期元组中的 PT006 错误名称类型”?
【发布时间】:2021-03-01 16:18:54
【问题描述】:

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

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

这是我的代码

import pytest


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

pip freeze | egrep flake8:

flake8==3.8.4
flake8-plugin-utils==1.3.1
flake8-pytest-style==1.3.0

如何修复错误?

【问题讨论】:

    标签: python python-3.x pytest flake8


    【解决方案1】:

    此错误由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
      
    • 更改pytest-parametrize-names-type 配置选项,将具有以下内容的名为.flake8 的文件添加到项目的根目录:
      [flake8]
      pytest-parametrize-names-type = csv
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 1970-01-01
      • 2020-01-05
      • 1970-01-01
      • 2019-12-18
      相关资源
      最近更新 更多