Beispiel #1
0
def output_fixtures(
    fixtures: List[Fixture],
    tests: List[Test],
    show_scopes: bool,
    show_docstrings: bool,
    show_dependencies: bool,
    show_dependency_trees: bool,
):
    generated_tests = itertools.chain.from_iterable(
        test.get_parameterised_instances() for test in tests
    )

    fixture_to_tests = fixtures_used_directly_by_tests(generated_tests)

    fixtures_to_parents, fixtures_to_children = fixture_parents_and_children(fixtures)

    for module, fixtures in group_by(fixtures, key=lambda f: f.module_name).items():
        rich_console.print(Rule(Text(module, style="title")))

        for fixture in fixtures:
            fixture_tree = make_fixture_information_tree(
                fixture,
                used_by_tests=fixture_to_tests[fixture],
                fixtures_to_children=fixtures_to_children,
                fixtures_to_parents=fixtures_to_parents,
                show_scopes=show_scopes,
                show_docstrings=show_docstrings,
                show_dependencies=show_dependencies,
                show_dependency_trees=show_dependency_trees,
            )
            rich_console.print(fixture_tree)
Beispiel #2
0
def output_fixtures(
    fixtures: List[Fixture],
    tests: List[Test],
    show_scopes: bool,
    show_docstrings: bool,
    show_dependencies: bool,
    show_dependency_trees: bool,
):
    generated_tests = itertools.chain.from_iterable(
        test.get_parameterised_instances() for test in tests)

    fixture_to_tests = fixtures_used_directly_by_tests(generated_tests)

    fixtures_to_parents, fixtures_to_children = fixture_parents_and_children(
        fixtures)

    for fixture in fixtures:
        output_fixture_information(
            fixture,
            used_by_tests=fixture_to_tests[fixture],
            fixtures_to_children=fixtures_to_children,
            fixtures_to_parents=fixtures_to_parents,
            show_scopes=show_scopes,
            show_docstrings=show_docstrings,
            show_dependencies=show_dependencies,
            show_dependency_trees=show_dependency_trees,
        )
Beispiel #3
0
def _():
    @fixture
    def f():
        pass

    t = Test(lambda f=f: None, module_name="")

    assert fixtures_used_directly_by_tests([t]) == {Fixture(f): [t]}
Beispiel #4
0
def _():
    @fixture
    def parent():
        pass

    @fixture
    def child():
        pass

    t = Test(lambda c=child: None, module_name="")

    assert fixtures_used_directly_by_tests([t]) == {Fixture(child): [t]}
Beispiel #5
0
def _():
    @fixture
    def parent():
        pass

    @fixture
    def child():
        pass

    @fixture
    def not_used():
        pass

    t1 = Test(lambda c=child: None, module_name="")
    t2 = Test(lambda p=parent, c=child: None, module_name="")
    t3 = Test(lambda _: None, module_name="")

    assert fixtures_used_directly_by_tests([t1, t2, t3]) == {
        Fixture(child): [t1, t2],
        Fixture(parent): [t2],
    }