Skip to content
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-31676: Fix test_imp.test_load_source() side effect #3871

Merged
merged 1 commit into from
Oct 13, 2017
Merged

bpo-31676: Fix test_imp.test_load_source() side effect #3871

merged 1 commit into from
Oct 13, 2017

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 3, 2017

test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.

https://bugs.python.org/issue31676

tmp_mod = type(sys.modules[__name__])(__name__)
with support.swap_item(sys.modules, __name__, tmp_mod):
with self.assertRaisesRegex(ValueError, 'embedded null'):
imp.load_source(__name__, __file__ + "\0")
Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 4, 2017

Choose a reason for hiding this comment

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

Wouldn't be safe to not use the name of an existing module?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.
@vstinner vstinner changed the title [WIP] bpo-31676: Fix test_imp.test_load_source() side effect bpo-31676: Fix test_imp.test_load_source() side effect Oct 9, 2017
@vstinner vstinner merged commit a505ecd into python:master Oct 13, 2017
@miss-islington
Copy link
Contributor

Thanks @Haypo for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@vstinner vstinner deleted the test_imp branch October 13, 2017 20:48
@bedevere-bot
Copy link

GH-3988 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 13, 2017
…H-3871)

test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.
(cherry picked from commit a505ecd)
Mariatta pushed a commit that referenced this pull request Oct 18, 2017
…3988)

test_load_source() now replaces the current __name__ module with a
temporary module to prevent side effects.
(cherry picked from commit a505ecd)
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.

5 participants