Exemplo n.º 1
0
def build_registry():
    @lcc.fixture(scope="session_prerun")
    def fix0():
        pass

    @lcc.fixture(scope="session")
    def fix1():
        pass

    @lcc.fixture(scope="suite")
    def fix2():
        pass

    @lcc.fixture(scope="test")
    def fix3():
        pass

    @lcc.fixture(names=["fix4", "fix5"])
    def fix_():
        pass

    registry = FixtureRegistry()
    for func in fix0, fix1, fix2, fix3, fix_:
        registry.add_fixtures(load_fixtures_from_func(func))

    return registry
Exemplo n.º 2
0
def test_registry_get_fixture_without_param_dependency():
    @lcc.fixture()
    def foo():
        return 42

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    assert registry.get_fixture_dependencies("foo") == []
Exemplo n.º 3
0
def test_registry_fixture_name():
    @lcc.fixture()
    def foo(fixture_name):
        pass

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.check_dependencies()
Exemplo n.º 4
0
def test_registry_fixture_without_params():
    @lcc.fixture()
    def myfixture():
        return 42

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(myfixture))
    registry.check_dependencies()
Exemplo n.º 5
0
def test_registry_forbidden_fixture_name():
    @lcc.fixture(scope="test")
    def fixture_name():
        return 0

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(fixture_name))
    with pytest.raises(exceptions.FixtureError) as excinfo:
        registry.check_dependencies()
    assert "forbidden" in str(excinfo.value)
Exemplo n.º 6
0
def test_registry_fixture_missing_dependency():
    @lcc.fixture()
    def bar(foo):
        return foo * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(bar))
    with pytest.raises(exceptions.LemonCheesecakeException) as excinfo:
        registry.check_dependencies()
    assert "does not exist" in str(excinfo.value)
Exemplo n.º 7
0
def test_registry_compatible_scope():
    @lcc.fixture(scope="session")
    def bar():
        return 21

    @lcc.fixture(scope="test")
    def foo(bar):
        return bar * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    registry.check_dependencies()
Exemplo n.º 8
0
def test_registry_get_fixture_with_param_dependency():
    @lcc.fixture()
    def bar():
        return 21

    @lcc.fixture()
    def foo(bar):
        return bar * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    assert registry.get_fixture_dependencies("foo") == ["bar"]
Exemplo n.º 9
0
def test_registry_fixture_with_params():
    @lcc.fixture()
    def foo():
        return 21

    @lcc.fixture()
    def bar(foo):
        return foo * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    registry.check_dependencies()
Exemplo n.º 10
0
def test_registry_incompatible_scope():
    @lcc.fixture(scope="test")
    def bar():
        return 21

    @lcc.fixture(scope="session")
    def foo(bar):
        return bar * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    with pytest.raises(exceptions.LemonCheesecakeException) as excinfo:
        registry.check_dependencies()
    assert 'incompatible' in str(excinfo.value)
Exemplo n.º 11
0
def test_registry_fixture_circular_dependency_direct():
    @lcc.fixture()
    def foo(bar):
        return bar * 2

    @lcc.fixture()
    def bar(foo):
        return foo * 2

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    with pytest.raises(exceptions.LemonCheesecakeException) as excinfo:
        registry.get_fixture_dependencies("foo")
    assert 'circular' in str(excinfo.value)
Exemplo n.º 12
0
def test_registry_get_fixture_with_params_dependency():
    @lcc.fixture()
    def zoub():
        return 21

    @lcc.fixture()
    def baz(zoub):
        return zoub

    @lcc.fixture()
    def bar(baz):
        return baz * 2

    @lcc.fixture()
    def foo(bar, baz):
        return bar * baz

    registry = FixtureRegistry()
    registry.add_fixtures(load_fixtures_from_func(foo))
    registry.add_fixtures(load_fixtures_from_func(bar))
    registry.add_fixtures(load_fixtures_from_func(baz))
    registry.add_fixtures(load_fixtures_from_func(zoub))
    assert registry.get_fixture_dependencies("foo") == ["zoub", "baz", "bar"]
Exemplo n.º 13
0
def build_fixture_registry(*funcs):
    registry = FixtureRegistry()
    for func in funcs:
        registry.add_fixtures(load_fixtures_from_func(func))
    return registry