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

Code before:
    result = pytester.runpytest(
        str(p1), "--pdbcls=really.invalid:Value", syspathinsert=True
    )
    result.stdout.fnmatch_lines(
        [
            "*= FAILURES =*",
            "E * --pdbcls: could not import 'really.invalid:Value': No module named *really*",
        ]
    )
    assert result.ret == 1

    result = pytester.runpytest(
        str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", syspathinsert=True
    )
    assert result.ret == 0
    result.stdout.fnmatch_lines(["*set_trace_called*", "* 1 passed in *"])

    # Ensure that it also works with --trace.
    result = pytester.runpytest(
        str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", "--trace", syspathinsert=True
    )
    assert result.ret == 0
    result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])


@pytest.mark.xfail(sys.version_info >= (3, 14), reason="I don't know why this fails")
def test_raises_bdbquit_with_eoferror(pytester: Pytester) -> None:
    """It is not guaranteed that DontReadFromInput's read is called."""
    p1 = pytester.makepyfile(
        """
        def input_without_read(*args, **kwargs):
            raise EOFError()

        def test(monkeypatch):
            import builtins
            monkeypatch.setattr(builtins, "input", input_without_read)
            __import__('pdb').set_trace()
        """
    )
    result = pytester.runpytest(str(p1))
    result.stdout.fnmatch_lines(["E *BdbQuit", "*= 1 failed in*"])
    assert result.ret == 1


def test_pdb_wrapper_class_is_reused(pytester: Pytester) -> None:
    p1 = pytester.makepyfile(
        """
        def test():
            __import__("pdb").set_trace()
            __import__("pdb").set_trace()


Review comment (bug):
```suggestion
@pytest.mark.xfail(sys.version_info >= (3, 14), reason="see https://github.com/python/cpython/issues/124703")
```

Code after:
    result = pytester.runpytest(
        str(p1), "--pdbcls=really.invalid:Value", syspathinsert=True
    )
    result.stdout.fnmatch_lines(
        [
            "*= FAILURES =*",
            "E * --pdbcls: could not import 'really.invalid:Value': No module named *really*",
        ]
    )
    assert result.ret == 1

    result = pytester.runpytest(
        str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", syspathinsert=True
    )
    assert result.ret == 0
    result.stdout.fnmatch_lines(["*set_trace_called*", "* 1 passed in *"])

    # Ensure that it also works with --trace.
    result = pytester.runpytest(
        str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", "--trace", syspathinsert=True
    )
    assert result.ret == 0
    result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])


@pytest.mark.xfail(
    sys.version_info >= (3, 14),
    reason="C-D now quits the test session, rather than failing the test. See https://github.com/python/cpython/issues/124703",
)
def test_raises_bdbquit_with_eoferror(pytester: Pytester) -> None:
    """It is not guaranteed that DontReadFromInput's read is called."""
    p1 = pytester.makepyfile(
        """
        def input_without_read(*args, **kwargs):
            raise EOFError()

        def test(monkeypatch):
            import builtins
            monkeypatch.setattr(builtins, "input", input_without_read)
            __import__('pdb').set_trace()
        """
    )
    result = pytester.runpytest(str(p1))
    result.assert_outcomes(failed=1)
    result.stdout.fnmatch_lines(["E *BdbQuit", "*= 1 failed in*"])
    assert result.ret == 1


def test_pdb_wrapper_class_is_reused(pytester: Pytester) -> None:
    p1 = pytester.makepyfile(
        """