def test_ok_without_parens():
    code = """
        import pytest

        @pytest.mark.foo
        def test_something():
            pass
    """
    config = DEFAULT_CONFIG._replace(mark_parentheses=False)
    assert_not_error(MarksVisitor, code, config=config)
def test_ok_without_parens():
    code = """
        import pytest

        @pytest.fixture
        def my_fixture():
            return 0
    """
    config = DEFAULT_CONFIG._replace(fixture_parentheses=False)
    assert_not_error(FixturesVisitor, code, config=config)
コード例 #3
0
def test_ok_with_parameters_regardless_of_config(mark_parentheses: bool):
    code = """
        import pytest

        @pytest.mark.foo(scope='module')
        def test_something():
            pass
    """
    config = DEFAULT_CONFIG._replace(mark_parentheses=mark_parentheses)
    assert_not_error(MarksVisitor, code, config=config)
def test_error_with_parens():
    code = """
        import pytest

        @pytest.yield_fixture
        def my_fixture():
            return 0
    """
    config = DEFAULT_CONFIG._replace(fixture_parentheses=False)
    assert_error(FixturesVisitor, code, DeprecatedYieldFixture, config=config)
def test_ok_single(values_cfg_type, values):
    code = f"""
        import pytest

        pytest.mark.parametrize(
            'name',
            {values!r},
        )
    """
    config = DEFAULT_CONFIG._replace(parametrize_values_type=values_cfg_type)
    assert_not_error(ParametrizeVisitor, code, config=config)
コード例 #6
0
def test_error_with_parens(code: str):
    config = DEFAULT_CONFIG._replace(mark_parentheses=False)
    assert_error(
        MarksVisitor,
        code,
        IncorrectMarkParenthesesStyle,
        config=config,
        mark_name='foo',
        expected_parens='',
        actual_parens='()',
    )
コード例 #7
0
def test_error_no_parens():
    code = """
        import pytest

        @pytest.mark.usefixtures
        def test_something():
            pass
    """
    config = DEFAULT_CONFIG._replace(mark_parentheses=False)
    assert_error(MarksVisitor,
                 code,
                 UseFixturesWithoutParameters,
                 config=config)
def test_ok_multiple(values_cfg_type, rows_cfg_type, values):
    code = f"""
        import pytest

        pytest.mark.parametrize(
            ('name1', 'name2'),
            {values!r},
        )
    """
    config = DEFAULT_CONFIG._replace(
        parametrize_values_type=values_cfg_type,
        parametrize_values_row_type=rows_cfg_type,
    )
    assert_not_error(ParametrizeVisitor, code, config=config)
コード例 #9
0
def test_ok_multiple(cfg_type, names):
    code = f"""
        import pytest

        pytest.mark.parametrize(
            {names!r},
            [
                ('a', 'b'),
                ('c', 'd'),
            ],
        )
    """
    config = DEFAULT_CONFIG._replace(parametrize_names_type=cfg_type)
    assert_not_error(ParametrizeVisitor, code, config=config)
def test_error_with_parens():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture():
            return 0
    """
    config = DEFAULT_CONFIG._replace(fixture_parentheses=False)
    assert_error(
        FixturesVisitor,
        code,
        IncorrectFixtureParenthesesStyle,
        config=config,
        expected_parens='',
        actual_parens='()',
    )
def test_error_with_parens():
    code = """
        import pytest

        @pytest.mark.foo()
        def test_something():
            pass
    """
    config = DEFAULT_CONFIG._replace(mark_parentheses=False)
    assert_error(
        MarksVisitor,
        code,
        IncorrectMarkParenthesesStyle,
        config=config,
        mark_name='foo',
        expected_parens='',
        actual_parens='()',
    )
def test_error_multiple_mixed(values_cfg_type, rows_cfg_type, values):
    code = f"""
        import pytest

        pytest.mark.parametrize(
            ('name1', 'name2'),
            {values!r},
        )
    """
    config = DEFAULT_CONFIG._replace(
        parametrize_values_type=values_cfg_type,
        parametrize_values_row_type=rows_cfg_type,
    )
    assert_error(
        ParametrizeVisitor,
        code,
        ParametrizeValuesWrongType,
        expected_type=_get_expected_type_str(values_cfg_type, rows_cfg_type),
        config=config,
    )
コード例 #13
0
def test_error_multiple(cfg_type, names):
    code = f"""
        import pytest

        pytest.mark.parametrize(
            {names!r},
            [
                ('a', 'b'),
                ('c', 'd'),
            ],
        )
    """
    config = DEFAULT_CONFIG._replace(parametrize_names_type=cfg_type)
    assert_error(
        ParametrizeVisitor,
        code,
        ParametrizeNamesWrongType,
        expected_type=cfg_type.value,
        config=config,
    )
コード例 #14
0
def test_ok_without_parens(code: str):
    config = DEFAULT_CONFIG._replace(mark_parentheses=False)
    assert_not_error(MarksVisitor, code, config=config)