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

Code before:
                "*test_2*",
                "*test_3*",
            ]
        )

    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")

Review comment (suggestion):
Did you mean:


```suggestion
        result = pytester.runpython("-W", "default")
```

Code after:
                "*test_2*",
                "*test_3*",
            ]
        )

    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
            """
        )