예제 #1
0
def test_ok():
    code = """
        def test_something():
            with pytest.raises(AttributeError):
                [].size
    """
    assert_not_error(RaisesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_trivial_with(maybe_async):
    code = f"""
        async def test_something():
            with pytest.raises(AttributeError):
                {maybe_async}with context_manager_under_test():
                    pass
    """
    assert_not_error(RaisesVisitor, code, config=DEFAULT_CONFIG)
예제 #3
0
def test_ok_no_parameters():
    code = """
        import pytest

        def test_xxx():
            assert 1 == 1
    """
    assert_not_error(UnittestAssertionVisitor, code)
def test_if_statment_non_assignment():
    code = dedent("""
        if x == 1:
            print(x)
        else:
            print(x+1)
    """)
    assert_not_error(IfStatementsVisitor, code)
def test_if_statment_different_variable_assignment():
    code = dedent("""
        if x == 1:
            y = 2
        else:
            z = 5
    """)
    assert_not_error(IfStatementsVisitor, code)
예제 #6
0
def test_ok_not_fixture():
    code = """
        import pytest

        @pytest.mark.usefixtures('a')
        def test_something():
            pass
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
예제 #7
0
def test_ok_another_mark_with_parens():
    code = """
        import pytest

        @pytest.mark.foo()
        def test_something():
            pass
    """
    assert_not_error(MarksVisitor, code, config=DEFAULT_CONFIG)
예제 #8
0
def test_ok_not_fixture_no_parens():
    code = """
        import pytest

        @pytest.mark.asyncio
        async def test_something():
            pass
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_ignoring_yield_from():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture():
            yield from some_generator()
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_simple():
    code = """
        import pytest

        @pytest.fixture()
        def _patch_something(mocker):
            mocker.patch('some.thing')
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_if_statment_multiple_lines():
    code = dedent("""
        if x == 1:
            y = x + 1
            z = 5
        else:
            z = 6
    """)
    assert_not_error(IfStatementsVisitor, code)
def test_ok_only_kwargs():
    code = """
        import pytest

        @pytest.fixture(scope='module')
        def my_fixture():
            return 0
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_no_parameters():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture():
            return 0
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
예제 #14
0
def test_ok_different_error_from_config():
    code = """
        import pytest

        def test_something():
            with pytest.raises(ZeroDivisionError):
                raise ZeroDivisionError("Can't divide by 0")
    """
    assert_not_error(RaisesVisitor, code, config=DEFAULT_CONFIG)
예제 #15
0
def test_ok_with_return():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture(mocker):
            return 0
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
예제 #16
0
def test_ok():
    code = """
        import pytest

        def test_something():
            with pytest.raises(UnicodeError):
                pass
    """
    assert_not_error(RaisesVisitor, code, config=DEFAULT_CONFIG)
예제 #17
0
def test_ok():
    code = """
        import pytest

        def test_something():
            with pytest.raises(ValueError, match="Can't divide by 0"):
                raise ValueError("Can't divide by 0")
    """
    assert_not_error(RaisesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_no_parameters():
    code = """
        import pytest

        @pytest.mark.foo()
        def test_something():
            pass
    """
    assert_not_error(MarksVisitor, code, config=DEFAULT_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)
예제 #20
0
def test_ok_nested_function():
    code = """
        @pytest.fixture()
        def _any_fixture(mocker):
            def nested_function():
                return 1

            mocker.patch('...', nested_function)
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
예제 #21
0
def test_ok_with_yield():
    code = """
        import pytest

        @pytest.fixture()
        def activate_context():
            with get_context() as context:
                yield context
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_class():
    code = """
        import pytest

        @pytest.mark.foo()
        class TestClass:
            def test_something():
                pass
    """
    assert_not_error(MarksVisitor, code, config=DEFAULT_CONFIG)
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)
예제 #24
0
def test_ok_single():
    code = """
        import pytest

        pytest.mark.parametrize(
            'name',
            ['a', 'b', 'c'],
        )
    """
    assert_not_error(ParametrizeVisitor, code, config=DEFAULT_CONFIG)
예제 #25
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_ok_other_request():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture():
            request = get_request()
            request.addfinalizer(finalizer)
            return request
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_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)
def test_ok_yield():
    code = """
        import pytest

        @pytest.fixture()
        def my_fixture():
            resource = acquire_resource()
            yield resource
            resource.release()
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
예제 #29
0
def test_ok_abstract_with_from_import():
    code = """
        from abc import abstractmethod

        import pytest

        class BaseTest:
            @pytest.fixture()
            @abstractmethod
            def _my_fixture():
                return NotImplemented
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)
def test_ok_abstract_with_import_abc():
    code = """
        import abc

        import pytest

        class BaseTest:
            @pytest.fixture()
            @abc.abstractmethod
            def my_fixture():
                raise NotImplementedError
    """
    assert_not_error(FixturesVisitor, code, config=DEFAULT_CONFIG)