Skip to content

Comments

feat: swev-id: pytest-dev__pytest-5787 preserve xdist exception chains#20

Open
casey-brooks wants to merge 1 commit intopytest-dev__pytest-5787from
casey/fix-xdist-chained-exc-serialization
Open

feat: swev-id: pytest-dev__pytest-5787 preserve xdist exception chains#20
casey-brooks wants to merge 1 commit intopytest-dev__pytest-5787from
casey/fix-xdist-chained-exc-serialization

Conversation

@casey-brooks
Copy link

Summary

  • carry ExceptionChainRepr data through BaseReport JSON helpers
  • reconstruct chained exceptions during deserialization while keeping legacy path intact
  • add regression coverage for JSON, hook, and xdist round-trips

Testing

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 . .venv/bin/activate && pytest testing/test_reports_chain.py -q
  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 . .venv/bin/activate && pytest testing/test_reports.py -q
  • . .venv/bin/activate && flake8 src/_pytest/reports.py testing/test_reports_chain.py

Reproduction

Reproducer from #16:

def test_chained_exception_with_from():
    try:
        try:
            raise ValueError(11)
        except Exception as e1:
            raise ValueError(12) from e1
    except Exception as e2:
        raise ValueError(13) from e2


def test_chained_exception_without_from():
    try:
        try:
            raise ValueError(21)
        except Exception:
            raise ValueError(22)
    except Exception:
        raise ValueError(23)

Before this change, running with pytest -n auto would only show E ValueError: 13 (or E ValueError: 23) on the controller, while a local run displayed the full chain. After the fix, the xdist run includes the cause/context banners ("During handling ..." / "The above exception ...") the same as a local run.

Resolves #16

@casey-brooks casey-brooks requested a review from a team December 25, 2025 20:37
@casey-brooks
Copy link
Author

Local Verification

  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 . .venv/bin/activate && pytest testing/test_reports_chain.py -q → 3 passed
  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 . .venv/bin/activate && pytest testing/test_reports.py -q → 14 passed
  • . .venv/bin/activate && flake8 src/_pytest/reports.py testing/test_reports_chain.py → no findings

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Carrying the chain information through _to_json/_from_json restores the missing context for xdist, and the new regression tests cover the JSON, hook, and worker/controller paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants