All tests fail with 'EXITED with status 3' on pytest 9.2.0 (TestReport._id is not marshallable)

未关闭 适合新手
#113 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
testing

调研方向

故障来自 serialize_report(),它在子进程用 marshal.dumps() 发送之前复制了 TestReport.dict。先在 pytest 9.2.0 和 --forked 下用 test_min.py 示例复现问题,然后检查报告字典中哪个值无法被 marshal 序列化。完成的标准是:在 pytest 9.2.0 下使用 --forked 的运行通过;并且当确实发生失败时,子进程的异常会在 os._exit(3) 之前被打印出来。

由索引模型根据 Issue 内容生成。

描述

With pytest 9.2.0, every test run under --forked fails, including ones that pass, with running the test EXITED with status 3. pytest 9.1.1 works.

Reproduce

# test_min.py
def test_ok():
    assert True
$ pip install pytest==9.2.0 pytest-forked==1.7.5
$ pytest --forked -q test_min.py
FAILED test_min.py::test_ok - .../test_min.py:1: running the test EXITED with status 3
1 failed

Seen on macOS (Darwin 27.2, Python 3.14.7) and on GitHub's ubuntu-latest and macOS runners.

Cause

pytest 9.2.0 adds a private _id attribute to TestReport, holding a NodeId object. serialize_report() copies rep.__dict__ and the child sends it with marshal.dumps(), which raises ValueError: unmarshallable object on NodeId. The child catches the exception and exits with EXITSTATUS_EXCEPTION (3), so the actual error is never shown.

Checking each value of serialize_report(report) with marshal.dumps shows _id (type NodeId) is the only one that fails under 9.2.0, for the setup, call and teardown reports. There are no failures under 9.1.1.

Possible fix

Drop or stringify values marshal can't handle in serialize_report(), e.g. skip private (_-prefixed) keys, or convert unknown types with str(). pytest-xdist's report serialization goes through config.hook.pytest_report_to_serialize / pytest_report_from_serialized, which pytest keeps compatible. Using those hooks would avoid depending on TestReport.__dict__ at all.

It would also help to print the child's exception (or write it to the stderr capture) before os._exit(3), so the next failure of this kind is self-explanatory.

主要语言
Python
星标
84
派生
30
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytest-dev/pytest-forked 的其他 Issue

查看 pytest-dev/pytest-forked 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。