Skip to content

Modernize ConftestImportFailure to use the exception chain - #14943

Draft
RonnyPfannschmidt wants to merge 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:conftest-import-failure-modernize
Draft

RonnyPfannschmidt wants to merge 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:conftest-import-failure-modernize

Conversation

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Stacked on #14824 — review only the last commit; the first is that PR.

Gives ConftestImportFailure the same shape PluginImportFailure got in #14824: a bare Exception subclass whose argument is the conftest path, with the original error carried by raise ... from on __cause__ instead of a hand-rolled cause attribute duplicating the chain. The custom __init__ and __str__ go away; str(e) is the path, which is exactly what both message consumers want.

Why this is safe:

  • the cause attribute is young — introduced in 8.0 (e1074f9) replacing the old excinfo triplet, without deprecation;
  • the class is private to _pytest.config (not exported as pytest.*), and a GitHub code search finds no external importers, only vendored copies of pytest itself;
  • all five internal consumers (print_conftest_import_error, the --help/--version grace path, Node._repr_failure_py unwrapping, --pdb post-mortem unwrapping, _main) are updated in this PR.

No user-visible output changes.

🤖 Written by Claude Code (Claude Fable 5); reviewed and submitted by @RonnyPfannschmidt.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 26, 2026
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the conftest-import-failure-modernize branch 4 times, most recently from c5e0b6b to 3e02d6b Compare August 27, 2026 19:58
Give ConftestImportFailure the same shape PluginImportFailure just got:
a bare Exception subclass whose argument is the conftest path, with the
original error carried by `raise ... from` on __cause__ instead of a
hand-rolled `cause` attribute duplicating it. The custom __init__ and
__str__ go away; str(e) is the path, which is exactly what the two
message consumers want.

The `cause` attribute dates to 8.0 (e1074f9), which replaced the old
excinfo triplet without deprecation; the class is private to
_pytest.config and a code search finds no external consumers, only
vendored copies of pytest itself.

No user-visible output changes.

Co-Authored-By: Claude Fable 5 <ai@anthropic.com>
Co-Authored-By: Claude Code <ai@anthropic.com>
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the conftest-import-failure-modernize branch from 3e02d6b to 15321ee Compare September 15, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant