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

Code before:
        """
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(["collected 1 item"])

    def test_rewrite(self, pytester: Pytester, monkeypatch) -> None:
        config = pytester.parseconfig()
        f = StringIO()
        monkeypatch.setattr(f, "isatty", lambda *args: True)
        tr = TerminalReporter(config, f)
        tr._tw.fullwidth = 10
        tr.write("hello")
        tr.rewrite("hey", erase=True)
        assert f.getvalue() == "hello" + "\r" + "hey" + (6 * " ")

    @pytest.mark.parametrize("category", ["foo", "failed", "error", "passed"])
    def test_report_teststatus_explicit_markup(
        self, monkeypatch: MonkeyPatch, pytester: Pytester, color_mapping, category: str
    ) -> None:
        """Test that TerminalReporter handles markup explicitly provided by
        a pytest_report_teststatus hook."""
        monkeypatch.setenv("PY_COLORS", "1")
        pytester.makeconftest(
            f"""
            def pytest_report_teststatus(report):
                return '{category}', 'F', ('FOO', {{'red': True}})
        """
        )
        pytester.makepyfile(
            """
            def test_foobar():
                pass
        """
        )

        result = pytester.runpytest("-v")
        assert not result.stderr.lines
        result.stdout.fnmatch_lines(
            color_mapping.format_for_fnmatch(["*{red}FOO{reset}*"])
        )

    def test_verbose_skip_reason(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            import pytest

            @pytest.mark.skip(reason="123")
            def test_1():
                pass

            @pytest.mark.xfail(reason="456")

Review comment (suggestion):
It's probably safer to use a string repr for cases when it gets to have a single quote inside for whatever reason:
```suggestion
                return {category !r}, 'F', ('FOO', {{'red': True}})
```

Code after:
        )
        result = pytester.runpytest()
        result.stdout.fnmatch_lines(["collected 1 item"])

    def test_rewrite(self, pytester: Pytester, monkeypatch) -> None:
        config = pytester.parseconfig()
        f = StringIO()
        monkeypatch.setattr(f, "isatty", lambda *args: True)
        tr = TerminalReporter(config, f)
        tr._tw.fullwidth = 10
        tr.write("hello")
        tr.rewrite("hey", erase=True)
        assert f.getvalue() == "hello" + "\r" + "hey" + (6 * " ")

    @pytest.mark.parametrize("category", ["foo", "failed", "error", "passed"])
    def test_report_teststatus_explicit_markup(
        self, monkeypatch: MonkeyPatch, pytester: Pytester, color_mapping, category: str
    ) -> None:
        """Test that TerminalReporter handles markup explicitly provided by
        a pytest_report_teststatus hook."""
        monkeypatch.setenv("PY_COLORS", "1")
        pytester.makeconftest(
            f"""
            def pytest_report_teststatus(report):
                return {category !r}, 'F', ('FOO', {{'red': True}})
        """
        )
        pytester.makepyfile(
            """
            def test_foobar():
                pass
        """
        )

        result = pytester.runpytest("-v")
        assert not result.stderr.lines
        result.stdout.fnmatch_lines(
            color_mapping.format_for_fnmatch(["*{red}FOO{reset}*"])
        )

    def test_verbose_skip_reason(self, pytester: Pytester) -> None:
        pytester.makepyfile(
            """
            import pytest

            @pytest.mark.skip(reason="123")
            def test_1():
                pass

            @pytest.mark.xfail(reason="456")
            def test_2():