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 build_fixture_registry(project, cli_args):
    registry = FixtureRegistry()
    registry.add_fixture(BuiltinFixture("cli_args", lambda: cli_args))
    registry.add_fixture(BuiltinFixture("project_dir", lambda: project.get_project_dir()))
    for fixture in project.get_fixtures():
        registry.add_fixture(fixture)
    registry.check_dependencies()
    return registry
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
def run_suites(suites,
               fixtures=None,
               backends=None,
               tmpdir=None,
               force_disabled=False,
               stop_on_failure=False,
               report_saving_strategy=None):
    if fixtures is None:
        fixture_registry = FixtureRegistry()
    else:
        if isinstance(fixtures, FixtureRegistry):
            fixture_registry = fixtures
        else:
            fixture_registry = build_fixture_registry(*fixtures)

    if backends is None:
        backends = []

    if tmpdir:
        event_manager = runner.initialize_event_manager(suites,
                                                        backends,
                                                        tmpdir.strpath,
                                                        report_saving_strategy,
                                                        nb_threads=1)
        runner.run_suites(suites,
                          fixture_registry,
                          event_manager,
                          force_disabled=force_disabled,
                          stop_on_failure=stop_on_failure)
    else:
        report_dir = tempfile.mkdtemp()
        event_manager = runner.initialize_event_manager(suites,
                                                        backends,
                                                        report_dir,
                                                        report_saving_strategy,
                                                        nb_threads=1)
        try:
            runner.run_suites(suites,
                              fixture_registry,
                              event_manager,
                              force_disabled=force_disabled,
                              stop_on_failure=stop_on_failure)
        finally:
            shutil.rmtree(report_dir)

    report = get_runtime().report
    dump_report(report)

    return report
Exemplo n.º 12
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.º 13
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.º 14
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.º 15
0
def build_fixture_registry(*funcs):
    registry = FixtureRegistry()
    for func in funcs:
        registry.add_fixtures(load_fixtures_from_func(func))
    return registry