def test_scoped_fixture_teardown_order(pytester: Pytester) -> None:
    """
    Make sure teardowns happen in reverse order of setup with scoped fixtures, when
    a later test only depends on a subset of scoped fixtures.

    Regression test for https://github.com/pytest-dev/pytest/issues/1489
    """
    pytester.makepyfile(
        """
        from typing import Generator

        import pytest


        last_executed = ""


        @pytest.fixture(scope="module")
        def fixture_1() -> Generator[None, None, None]:
            global last_executed
            assert last_executed == ""
            last_executed = "fixture_1_setup"
            yield
            assert last_executed == "fixture_2_teardown"
            last_executed = "fixture_1_teardown"


        @pytest.fixture(scope="module")
        def fixture_2() -> Generator[None, None, None]:
            global last_executed
            assert last_executed == "fixture_1_setup"
            last_executed = "fixture_2_setup"
            yield
            assert last_executed == "run_test"
            last_executed = "fixture_2_teardown"


        def test_fixture_teardown_order(fixture_1: None, fixture_2: None) -> None:
            global last_executed
            assert last_executed == "fixture_2_setup"
            last_executed = "run_test"


        def test_2(fixture_1: None) -> None:
            # This would previously queue an additional teardown of fixture_1,
            # despite fixture_1's value being cached, which caused fixture_1 to be
            # torn down before fixture_2 - violating the rule that teardowns should
            # happen in reverse order of setup.
            pass
        """
    )
    result = pytester.runpytest()
    assert result.ret == 0

    Make sure teardowns happen in reverse order of setup with scoped fixtures, when
    a later test only depends on a subset of scoped fixtures.

    Regression test for https://github.com/pytest-dev/pytest/issues/1489
    
testing/python/fixtures.py