Skip to content

Unittest: self-referencing explicit exception cause results in infinite loop #98458

Closed
@AlexTate

Description

@AlexTate

Bug report

If an exception is raised with a self-referencing __cause__ or __context__ then TestResult._clean_tracebacks() in result.py enters an infinite loop.

Minimal example 1:

try:
    raise Exception()
except Exception as e:
    raise e from e

Minimal example 2:

try:
    e = Exception()
    raise e from e
except Exception as e:
    raise e

Identified Cause

Self-references are not checked while unwinding the chained exception on line 216 of result.py

Your environment

  • CPython versions tested on: 3.9, 3.10
  • Operating system and architecture: macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions