Skip to content

gh-37883: Safely skip test_resource file size tests when limits are strict#145579

Open
Shrey-N wants to merge 8 commits intopython:mainfrom
Shrey-N:fixy-branch
Open

gh-37883: Safely skip test_resource file size tests when limits are strict#145579
Shrey-N wants to merge 8 commits intopython:mainfrom
Shrey-N:fixy-branch

Conversation

@Shrey-N
Copy link
Contributor

@Shrey-N Shrey-N commented Mar 6, 2026

This fixes the Standing issue #37883 where test_resource would fail on systems with file size limitations

Previous attempts (like #140872) tried to introduce massive refactoring and helper classes. Based on reviewer feedback I read there, I have tried a minimal fix

  • It checks if the system's hard limit is large enough, and if the OS actually allows the limit to be modified. If not, it uses self.skipTest with an informative message rather than failing with an unhandled OSError or ValueError.
  • It replaces the fragile dual try...finally resource restoration blocks with self.addCleanup(), guaranteeing that limits are reset even during a test assertion failure.

Fixes #37883

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label Mar 6, 2026
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 6, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@Shrey-N
Copy link
Contributor Author

Shrey-N commented Mar 6, 2026

I have added a news entry, though I am not sure if it's necessary or for this fix, Please let me know if I should remove it :)

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

This looks good!

We don't need a NEWS entry for a test-only change.

@Shrey-N
Copy link
Contributor Author

Shrey-N commented Mar 10, 2026

@encukou Alrighty thank you, I was confused as to add it or not so thank you for clearing that up :), also I will incorporate your reviews in a second :)

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

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_resource fails when file size is limited

2 participants