Example #1
0
def _(cache: FixtureCache = cache):
    cache.teardown_fixtures_for_scope(Scope.Module, testable_test.path)

    fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Module,
                                                    testable_test.path)

    assert fixtures_at_scope == {}
Example #2
0
def _(cache: FixtureCache = cache, events: List = recorded_events):
    cache.teardown_fixtures_for_scope(
        Scope.Module,
        testable_test.path,
        capture_output=False  # type: ignore[attr-defined]
    )

    assert events == ["teardown m"]
Example #3
0
def _(cache: FixtureCache = cache):
    cache.teardown_fixtures_for_scope(
        Scope.Module,
        testable_test.path,
        capture_output=True  # type: ignore[attr-defined]
    )

    fixtures_at_scope = cache.get_fixtures_at_scope(
        Scope.Module, testable_test.path)  # type: ignore[attr-defined]

    assert fixtures_at_scope == {}
Example #4
0
def _():
    error = StopIteration("oh no")

    @fixture
    def raises_in_teardown():
        yield "a"
        print("stdout")
        sys.stderr.write("stderr")
        raise error

    @testable_test
    def t(fix=raises_in_teardown):
        pass

    cache = FixtureCache()
    t = Test(t, "")
    t.resolver.resolve_args(cache)

    teardown_results: List[TeardownResult] = cache.teardown_fixtures_for_scope(
        scope=Scope.Test, scope_key=t.id, capture_output=True)

    assert len(teardown_results) == 1
    assert teardown_results[0].captured_exception == error
    # Ensure that we still capture stdout, stderr on exception
    assert teardown_results[0].sout == "stdout\n"
    assert teardown_results[0].serr == "stderr"
Example #5
0
def _(cache: FixtureCache = cache):
    teardown_results = cache.teardown_fixtures_for_scope(Scope.Module,
                                                         testable_test.path,
                                                         capture_output=True)

    assert len(teardown_results) == 1
    assert teardown_results[0].sout == "stdout\n"
    assert teardown_results[0].serr == "stderr"
Example #6
0
def _(cache: FixtureCache = cache, t: Test = my_test):
    teardown_results: List[TeardownResult] = cache.teardown_fixtures_for_scope(
        Scope.Test, t.id, capture_output=True)

    # There are 4 fixtures injected into the test. Only 2 are test-scoped, and teardown
    # code only runs in 1 of those.
    assert len(teardown_results) == 1
    assert teardown_results[0].captured_exception is None
    assert teardown_results[0].sout == "stdout\n"
    assert teardown_results[0].serr == "stderr"
Example #7
0
def _(cache: FixtureCache = cache, events: List = recorded_events):
    cache.teardown_fixtures_for_scope(Scope.Module, testable_test.path)

    assert events == ["teardown m"]
Example #8
0
def _(cache: FixtureCache = cache,
      t: Test = my_test,
      events: List = recorded_events):
    cache.teardown_fixtures_for_scope(Scope.Test, t.id)

    assert events == ["teardown t"]
Example #9
0
def _(cache: FixtureCache = cache, t: Test = my_test):
    cache.teardown_fixtures_for_scope(Scope.Test, t.id)

    fixtures_at_scope = cache.get_fixtures_at_scope(Scope.Test, t.id)

    assert fixtures_at_scope == {}