Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-39986: Make test_listdir from test_os more robust#19035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MatzeB wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromMatzeB:fix-issue-39986

Conversation

MatzeB
Copy link
Contributor

@MatzeBMatzeB commentedMar 17, 2020
edited by bedevere-bot
Loading

The test_listdir test of test_os assumed that calling listdir on the
root directory twice gives the same results, however this can fail if
unrelated process create files in the root directory in between the two
calls. This changes the test to create a temporary directory with two
files inside and call listdir on this temporary directory instead.

https://bugs.python.org/issue39986

The test_listdir test of test_os assumed that calling listdir on theroot directory twice gives the same results, however this can fail ifunrelated process create files in the root directory in between the twocalls. This changes the test to create a temporary directory with twofiles inside and call listdir on this temporary directory instead.
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
open("a.txt", "w").close()
open("test_file.foo", "w").close()
Copy link
Member

Choose a reason for hiding this comment

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

Can you write something in the files just to make sure they are created on all platforms?

os.chdir(tmpdir)
open("a.txt", "w").close()
open("test_file.foo", "w").close()
self.assertEqual(set(os.listdir()), set(os.listdir(tmpdir)))
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to check that the file you created are in the output?

Comment on lines +2209 to +2213
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
open("a.txt", "w").close()
open("test_file.foo", "w").close()
self.assertEqual(set(os.listdir()), set(os.listdir(tmpdir)))

Choose a reason for hiding this comment

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

There is already a directory with a known content:self.dir.

Suggested change
withtempfile.TemporaryDirectory()astmpdir:
os.chdir(tmpdir)
open("a.txt","w").close()
open("test_file.foo","w").close()
self.assertEqual(set(os.listdir()),set(os.listdir(tmpdir)))
os.chdir(self.dir)
self.assertEqual(set(os.listdir()),expected)

@serhiy-storchakaserhiy-storchaka added needs backport to 3.13bugs and security fixes and removed needs backport to 3.11only security fixes labelsMay 9, 2024
@hugovkhugovk removed the needs backport to 3.12only security fixes labelApr 10, 2025
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.14bugs and security fixes labelMay 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iritkatrieliritkatrieliritkatriel left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

Assignees
No one assigned
Labels
awaiting reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesskip newstestsTests in the Lib/test dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@MatzeB@iritkatriel@serhiy-storchaka@hugovk@the-knights-who-say-ni@ezio-melotti@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp