classification
Title: test_discovery_failed_discovery in test_unittest modifies sys.path
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, michael.foord, ned.deily, rbcollins, serhiy.storchaka, taleinat, vstinner
Priority: normal Keywords: patch

Created on 2018-06-03 12:03 by serhiy.storchaka, last changed 2018-06-13 10:08 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7433 merged taleinat, 2018-06-05 15:14
PR 7603 merged miss-islington, 2018-06-10 21:18
PR 7604 merged miss-islington, 2018-06-10 21:19
Messages (8)
msg318535 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-03 12:03
$ ./python -m test -v -m test_discovery_failed_discovery test_unittest
...
Warning -- sys.path was modified by test_unittest
  Before: (139720094056760, ['/home/serhiy/py/cpython', '/usr/local/lib/python38.zip', '/home/serhiy/py/cpython/Lib', '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug', '/home/serhiy/.local/lib/python3.8/site-packages'], ['/home/serhiy/py/cpython', '/usr/local/lib/python38.zip', '/home/serhiy/py/cpython/Lib', '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug', '/home/serhiy/.local/lib/python3.8/site-packages'])
  After:  (139720094056760, ['/home/serhiy/py/cpython', '/usr/local/lib/python38.zip', '/home/serhiy/py/cpython/Lib', '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug', '/home/serhiy/.local/lib/python3.8/site-packages'], ['/home/serhiy/py/cpython/build/test_python_8308/package', '/home/serhiy/py/cpython', '/usr/local/lib/python38.zip', '/home/serhiy/py/cpython/Lib', '/home/serhiy/py/cpython/build/lib.linux-x86_64-3.8-pydebug', '/home/serhiy/.local/lib/python3.8/site-packages']) 
test_unittest failed (env changed)
msg318739 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2018-06-05 11:59
It seems that adding a directory to sys.path is the intended behavior of `loader.discover()`. Should the test be restoring sys.path back to it original value when it's done?

Also, shouldn't this test (and some others) be restoring sys.modules when they're done?
msg318747 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-06-05 12:55
Yes, and there are helpers in test.support and test.test_importlib.util.
msg319203 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2018-06-10 07:10
New changeset 4ab4695388fb9ec03a14d93e90ce50d832a920ec by Tal Einat in branch 'master':
bpo-33748: fix tests altering sys.path and sys.modules (GH-7433)
https://github.com/python/cpython/commit/4ab4695388fb9ec03a14d93e90ce50d832a920ec
msg319250 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-06-10 21:45
New changeset 298eb07faa66da9c588bd82db14a6eef64167ede by Ned Deily (Miss Islington (bot)) in branch '3.7':
bpo-33748: fix tests altering sys.path and sys.modules (GH-7433) (#7604)
https://github.com/python/cpython/commit/298eb07faa66da9c588bd82db14a6eef64167ede
msg319251 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-06-10 21:45
New changeset 040d4a7b5899b9635c6997c5ecb91f8299f0b352 by Ned Deily (Miss Islington (bot)) in branch '3.6':
bpo-33748: fix tests altering sys.path and sys.modules (GH-7433) (GH-7603)
https://github.com/python/cpython/commit/040d4a7b5899b9635c6997c5ecb91f8299f0b352
msg319252 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-06-10 21:51
Backported for 3.7.0rc1 and 3.6.6rc1.  Thanks, all!
msg319445 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-13 10:08
Note: Python 2.7 doesn't have the test_discovery_from_dotted_namespace_packages() test, so no backport to 2.7 is needed.
History
Date User Action Args
2018-06-13 10:08:50vstinnersetnosy: + vstinner
messages: + msg319445
2018-06-10 21:51:28ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg319252

stage: patch review -> resolved
2018-06-10 21:45:53ned.deilysetmessages: + msg319251
2018-06-10 21:45:21ned.deilysetnosy: + ned.deily
messages: + msg319250
2018-06-10 21:19:37miss-islingtonsetpull_requests: + pull_request7226
2018-06-10 21:18:16miss-islingtonsetpull_requests: + pull_request7225
2018-06-10 07:10:31taleinatsetmessages: + msg319203
2018-06-05 15:14:40taleinatsetkeywords: + patch
stage: patch review
pull_requests: + pull_request7059
2018-06-05 12:55:27serhiy.storchakasetmessages: + msg318747
2018-06-05 11:59:09taleinatsetnosy: + taleinat
messages: + msg318739
2018-06-03 12:03:13serhiy.storchakacreate