Skip to content

gh-158377: Restore unittest loader top-level dir when discovery fails - #158379

Closed
lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158377
Closed

lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158377

Conversation

@lazerg

@lazerg lazerg commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

discover() put the saved _top_level_dir back only at the end of a successful call, so a failed discovery left the loader pointing at the failed top-level directory. The restore now sits in a finally block. test_discover was asserting the leaked value after the ImportError, so its two checks now expect None.

Fixes #158377

@picnixz

picnixz commented Sep 29, 2026

Copy link
Copy Markdown
Member

(A Pr already exists sorry)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unittest.TestLoader.discover() leaves _top_level_dir set if discovery fails

2 participants