Repository: pytest-dev/pytest
File: testing/python/fixtures.py (Python)

Code before:

            def setup_module():
                assert DB_INITIALIZED

            def teardown_module():
                assert DB_INITIALIZED

            class TestClass(object):

                def setup_method(self, method):
                    assert DB_INITIALIZED

                def teardown_method(self, method):
                    assert DB_INITIALIZED

                def test_printer_1(self):
                    pass

                def test_printer_2(self):
                    pass
        """
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(["* 2 passed in *"])

    def test_parameterized_fixture_caching(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            import pytest
            from itertools import count

            CACHE_MISSES = count(0)

            def pytest_generate_tests(metafunc):
                if "my_fixture" in metafunc.fixturenames:
                    param = "d%s" % "1"
                    print("param id=%d" % id(param), flush=True)
                    metafunc.parametrize("my_fixture", [param, "d2"], indirect=True)

            @pytest.fixture(scope='session')
            def my_fixture(request):
                next(CACHE_MISSES)

            def test1(my_fixture):
                pass

            def test2(my_fixture):
                pass

            def teardown_module():
                assert next(CACHE_MISSES) == 2

Review comment (suggestion):
```suggestion
    def test_parameterized_fixture_caching(self, pytester: Pytester) -> None:
        """Regression test for #12600."""
```

Code after:

            def setup_module():
                assert DB_INITIALIZED

            def teardown_module():
                assert DB_INITIALIZED

            class TestClass(object):

                def setup_method(self, method):
                    assert DB_INITIALIZED

                def teardown_method(self, method):
                    assert DB_INITIALIZED

                def test_printer_1(self):
                    pass

                def test_printer_2(self):
                    pass
        """
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(["* 2 passed in *"])

    def test_parameterized_fixture_caching(self, pytester: Pytester) -> None:
        """Regression test for #12600."""
        pytester.makepyfile(
            """
            import pytest
            from itertools import count

            CACHE_MISSES = count(0)

            def pytest_generate_tests(metafunc):
                if "my_fixture" in metafunc.fixturenames:
                    # Use unique objects for parametrization (as opposed to small strings
                    # and small integers which are singletons).
                    metafunc.parametrize("my_fixture", [[1], [2]], indirect=True)

            @pytest.fixture(scope='session')
            def my_fixture(request):
                next(CACHE_MISSES)

            def test1(my_fixture):
                pass

            def test2(my_fixture):
                pass

            def teardown_module():