Skip to content

Conversation

@delta87
Copy link
Contributor

@delta87 delta87 commented Dec 26, 2024

This PR addresses issue #13083 by modifying the scandir function to handle the case where a non-existent directory is provided. Previously, the function did not return a result for such cases, potentially leading to unhandled errors. Now, if the directory does not exist, the function will return an empty list instead.

Changes made:

Updated scandir to catch FileNotFoundError and return an empty list if the directory does not exist.
Updated the function docstring to reflect the new behavior.
Testing:

Also two tests were added.
Closes #13083

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 26, 2024
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks a lot @delta87 for the contribution!

@nicoddemus nicoddemus enabled auto-merge (squash) January 6, 2025 11:12
@nicoddemus nicoddemus force-pushed the bugFix/scandir-empty-dir branch from bd13b60 to 835d81b Compare January 6, 2025 11:23
@nicoddemus nicoddemus disabled auto-merge January 6, 2025 11:23
@nicoddemus
Copy link
Member

Hmmm the failure is unrelated, will try to investigate this later.

@The-Compiler
Copy link
Member

Hmmm the failure is unrelated, will try to investigate this later.

Once the fix is in and this PR gets rebased, hopefully things are all green again!

@nicoddemus nicoddemus force-pushed the bugFix/scandir-empty-dir branch from 835d81b to 476e31a Compare January 8, 2025 20:27
@nicoddemus nicoddemus enabled auto-merge (squash) January 8, 2025 20:28
@nicoddemus nicoddemus merged commit 3214263 into pytest-dev:main Jan 8, 2025
28 checks passed
@patchback
Copy link

patchback bot commented Jan 8, 2025

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/3214263b2f0d17b265c40cf5f87d70357b9a219d/pr-13086

Backported as #13117

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
(cherry picked from commit 3214263)
nicoddemus pushed a commit that referenced this pull request Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
(cherry picked from commit 3214263)

Co-authored-by: delta87 <124760624+delta87@users.noreply.github.com>
@delta87 delta87 deleted the bugFix/scandir-empty-dir branch January 13, 2025 12:37
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.

Race condition: collection error when directory is deleted before scandir() runs

4 participants