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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-30441: Fix bug when modifying os.environ while iterating over it #2409
Changes from 1 commit
375f977
cac586f
6bbfe8c
2190931
3b15ce0
a061788
4c3f4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -835,6 +835,21 @@ def test_key_type(self): | |
self.assertIs(cm.exception.args[0], missing) | ||
self.assertTrue(cm.exception.__suppress_context__) | ||
|
||
def test_iter_error_when_os_environ_changes(self): | ||
def _iter_environ_change(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just use It may be worth to test also other iterators: |
||
for key, value in os.environ.items(): | ||
yield key, value | ||
|
||
iter_environ = _iter_environ_change() | ||
key, value = next(iter_environ) # start iteration over os.environ | ||
|
||
# add a new key in os.environ mapping | ||
new_key = "__{}".format(key) | ||
os.environ[new_key] = value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to remove the added key. |
||
|
||
next(iter_environ) # force iteration over modified mapping | ||
self.assertEqual(os.environ[new_key], value) | ||
|
||
|
||
class WalkTests(unittest.TestCase): | ||
"""Tests for os.walk().""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either inline
data
or rename it tokeys
. Add an explaining comment about atomicity of list() from dict.