How to fix "PT006 wrong name(s) type in @pytest.mark.parametrize, expected tuple"?
Asked Answered
F

1

6

When I run flake8 I get the following error:

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

Here is my code

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

How do I fix the error?

Faviolafavonian answered 1/3, 2021 at 16:18 Comment(0)
F
11

This error is generated by flake8-pytest-style. See https://github.com/m-burst/flake8-pytest-style/blob/master/docs/rules/PT006.md

You have two options:

  • Replace 'foo,bar' with ('foo', 'bar')
    import pytest
    
    
    @pytest.mark.parametrize(('foo', 'bar'), [(1, 1), (2, 2)])
    def test_foo(foo, bar):
        assert foo == bar
    
  • Change the pytest-parametrize-names-type configuration option by adding a file named .flake8 with the following contents to the root of your project:
    [flake8]
    pytest-parametrize-names-type = csv
    
Faviolafavonian answered 1/3, 2021 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.