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

Code before:

    def test_parametrize_generator_multiple_runs(self, pytester: Pytester) -> None:
        """Test that generators in parametrize work with multiple pytest.main() (deprecated)."""
        pytester.makepyfile(
            """
            import pytest

            def data_generator():
                yield 1
                yield 2

            @pytest.mark.parametrize("bar", data_generator())
            def test_foo(bar):
                pass

            if __name__ == '__main__':
                args = ["-q", "--collect-only"]
                pytest.main(args)  # First run - should work with warning
                pytest.main(args)  # Second run - should also work with warning
            """
        )
        result = pytester.runpytest("-W", "default")
        # Should see the deprecation warnings.
        result.stdout.fnmatch_lines(
            [
                "*PytestRemovedIn10Warning: The argvalues parameter*",
            ]
        )

    def test_parametrize_iterator_class_multiple_tests(
        self, pytester: Pytester
    ) -> None:
        """Test that iterators in parametrize on a class get exhausted (deprecated)."""
        pytester.makepyfile(
            """
            import pytest

            @pytest.mark.parametrize("n", iter(range(2)))
            class Test:
                def test_1(self, n):
                    pass

                def test_2(self, n):
                    pass
            """
        )
        result = pytester.runpytest("-v", "-W", "default")
        # Iterator gets exhausted after first test, second test gets no parameters.
        # This is deprecated.
        result.assert_outcomes(passed=2, skipped=1)
        # Should see the deprecation warnings.

Review comment (suggestion):
I understand we should see this appear twice?


```suggestion
                "*PytestRemovedIn10Warning: The argvalues parameter*",
                "*PytestRemovedIn10Warning: The argvalues parameter*",
```

Code after:

    def test_parametrize_generator_multiple_runs(self, pytester: Pytester) -> None:
        """Test that generators in parametrize work with multiple pytest.main() (deprecated)."""
        testfile = pytester.makepyfile(
            """
            import pytest

            def data_generator():
                yield 1
                yield 2

            @pytest.mark.parametrize("bar", data_generator())
            def test_foo(bar):
                pass

            if __name__ == '__main__':
                args = ["-q", "--collect-only"]
                pytest.main(args)  # First run - should work with warning
                pytest.main(args)  # Second run - should also work with warning
            """
        )
        result = pytester.run(sys.executable, "-Wdefault", testfile)
        # Should see the deprecation warnings.
        result.stdout.fnmatch_lines(
            [
                "*PytestRemovedIn10Warning: Passing a non-Collection iterable*",
                "*PytestRemovedIn10Warning: Passing a non-Collection iterable*",
            ]
        )

    def test_parametrize_iterator_class_multiple_tests(
        self, pytester: Pytester
    ) -> None:
        """Test that iterators in parametrize on a class get exhausted (deprecated)."""
        pytester.makepyfile(
            """
            import pytest

            @pytest.mark.parametrize("n", iter(range(2)))
            class Test:
                def test_1(self, n):
                    pass

                def test_2(self, n):
                    pass
            """
        )
        result = pytester.runpytest("-v", "-Wdefault")
        # Iterator gets exhausted after first test, second test gets no parameters.
        # This is deprecated.
        result.assert_outcomes(passed=2, skipped=1)