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

Code before:
    assert result.ret != 0


def test_disabled(pytester: Pytester) -> None:
    """Test option to disable fault handler in the command line."""
    pytester.makepyfile(
        """
    import faulthandler
    def test_disabled():
        assert not faulthandler.is_enabled()
    """
    )
    result = pytester.runpytest_subprocess("-p", "no:faulthandler")
    result.stdout.fnmatch_lines(["*1 passed*"])
    assert result.ret == 0


@pytest.mark.keep_ci_var
@pytest.mark.parametrize("enabled", [True, False])
def test_timeout(pytester: Pytester, enabled: bool) -> None:
    """Test option to dump tracebacks after a certain timeout.

    If faulthandler is disabled, no traceback will be dumped.
    """
    pytester.makepyfile(
        """
    import os, time
    def test_timeout():
        time.sleep(1 if "CI" in os.environ else 0.1)
    """
    )
    pytester.makeini(
        """
        [pytest]
        faulthandler_timeout = 0.01
        """
    )
    args = ["-p", "no:faulthandler"] if not enabled else []

    result = pytester.runpytest_subprocess(*args)
    tb_output = "most recent call first"
    if enabled:
        result.stderr.fnmatch_lines([f"*{tb_output}*"])
    else:
        assert tb_output not in result.stderr.str()
    result.stdout.fnmatch_lines(["*1 passed*"])
    assert result.ret == 0


@pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"])
def test_cancel_timeout_on_hook(monkeypatch, hook_name) -> None:

Review comment (bug):
I removed the `skip` mark on `test_timeout` to check whether the `keep_ci_var` works as expected.

Previously, this test would have failed with high probability on at least one of the CI runner. Now that we propagate the CI variable, it seems that this test pass on most of the CI runners but we got still got one failure: https://github.com/pytest-dev/pytest/actions/runs/17409387341/job/49422461654?pr=13684


Let me re-add the skip mark for now to decouple the different PRs.

Code after:
    assert result.ret != 0


def test_disabled(pytester: Pytester) -> None:
    """Test option to disable fault handler in the command line."""
    pytester.makepyfile(
        """
    import faulthandler
    def test_disabled():
        assert not faulthandler.is_enabled()
    """
    )
    result = pytester.runpytest_subprocess("-p", "no:faulthandler")
    result.stdout.fnmatch_lines(["*1 passed*"])
    assert result.ret == 0


@pytest.mark.keep_ci_var
@pytest.mark.parametrize(
    "enabled",
    [
        pytest.param(
            True, marks=pytest.mark.skip(reason="sometimes crashes on CI (#7022)")
        ),
        False,
    ],
)
def test_timeout(pytester: Pytester, enabled: bool) -> None:
    """Test option to dump tracebacks after a certain timeout.

    If faulthandler is disabled, no traceback will be dumped.
    """
    pytester.makepyfile(
        """
    import os, time
    def test_timeout():
        time.sleep(1 if "CI" in os.environ else 0.1)
    """
    )
    pytester.makeini(
        """
        [pytest]
        faulthandler_timeout = 0.01
        """
    )
    args = ["-p", "no:faulthandler"] if not enabled else []

    result = pytester.runpytest_subprocess(*args)
    tb_output = "most recent call first"
    if enabled:
        result.stderr.fnmatch_lines([f"*{tb_output}*"])