classification
Title: test_site fails if run after test_inspect
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, miss-islington, vstinner, xtreak, yan12125, yselivanov
Priority: normal Keywords: patch

Created on 2018-10-02 14:37 by yan12125, last changed 2018-10-04 19:34 by yselivanov. This issue is now closed.

Files
File name Uploaded Description Edit
cpython-failure.txt yan12125, 2018-10-02 14:37 Output of `./python -m test.regrtest -v test_inspect test_site`
Pull Requests
URL Status Linked Edit
PR 9696 merged inada.naoki, 2018-10-04 09:42
PR 9698 merged yan12125, 2018-10-04 12:57
PR 9701 merged miss-islington, 2018-10-04 16:47
PR 9702 merged miss-islington, 2018-10-04 16:47
Messages (9)
msg326881 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2018-10-02 14:37
$ ./python -m test.regrtest test_inspect test_site
    Run tests sequentially
    0:00:00 load avg: 0.03 [1/2] test_inspect
    0:00:00 load avg: 0.03 [2/2] test_site
    test test_site failed -- Traceback (most recent call last):
      File "/home/yen/Projects/cpython/Lib/test/test_site.py", line 400, in test_abs_paths_cached_None
        site.abs_paths()
      File "/home/yen/Projects/cpython/Lib/site.py", line 101, in abs_paths
        for m in set(sys.modules.values()):
    TypeError: unhashable type: 'dict'

    test_site failed


If I run test_inspect or test_site individually, both pass. Full log can be found in the attached file.

Environment: Arch Linux x86_64 latest. CPython commit 81574b80e92554adf75c13fa42415beb8be383cb, configured with `./configure`
msg326882 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-02 14:39
You can try to limit the number of tests needed to reproduce the bug using:

./python -m test.bisect -n 5 test_inspect test_site
msg326884 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2018-10-02 14:57
The failing test was added with d4c76d960b8b286b75c933780416ace9cda682fd


commit d4c76d960b8b286b75c933780416ace9cda682fd
Author: INADA Naoki <methane@users.noreply.github.com>
Date:   Mon Oct 1 21:10:37 2018 +0900

    bpo-30167: Add test for module.__cached__ is None (GH-7617)

diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index dc59e5917c..33a8f1a44c 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -389,6 +389,17 @@ class ImportSideEffectTests(unittest.TestCase):
                             "expected absolute path, got {}"
                             .format(os__cached__.decode('ascii')))

+    def test_abs_paths_cached_None(self):
+        """Test for __cached__ is None.
+
+        Regarding to PEP 3147, __cached__ can be None.
+
+        See also: https://bugs.python.org/issue30167
+        """
+        sys.modules['test'].__cached__ = None
+        site.abs_paths()
+        self.assertIsNone(sys.modules['test'].__cached__)
+


# Latest master

➜  cpython git:(master) ./python.exe -m test.regrtest test_inspect test_site
Run tests sequentially
0:00:00 load avg: 1.75 [1/2] test_inspect
0:00:02 load avg: 1.75 [2/2] test_site
test test_site failed -- Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_site.py", line 400, in test_abs_paths_cached_None
    site.abs_paths()
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/site.py", line 101, in abs_paths
    for m in set(sys.modules.values()):
TypeError: unhashable type: 'dict'

test_site failed

== Tests result: FAILURE ==

1 test OK.

1 test failed:
    test_site

Total duration: 2 sec 868 ms
Tests result: FAILURE


➜  cpython git:(master) git checkout d4c76d960b8b286b75c933780416ace9cda682fd~1 Lib/test/test_site.py
➜  cpython git:(master) ✗ ./python.exe -m test.regrtest test_inspect test_site
Run tests sequentially
0:00:00 load avg: 1.49 [1/2] test_inspect
0:00:02 load avg: 1.49 [2/2] test_site

== Tests result: SUCCESS ==

All 2 tests OK.

Total duration: 2 sec 848 ms
Tests result: SUCCESS

Adding INADA Naoki for thoughts.


Thanks
msg326885 - (view) Author: Chih-Hsuan Yen (yan12125) * Date: 2018-10-02 16:05
Thanks very much for the test.bisect hint! After some more trials, I guess it's an issue in the `inspect` module rather than the newly-added test in test_site. Here's an example script:


import inspect
import sys
import _testcapi

builtin = _testcapi.docstring_with_signature_with_defaults
spec = inspect.getfullargspec(builtin)
print(type(sys.modules['__builtins__']))


After inspect.getfullargspec(), sys.modules['__builtins__'] is a dict. That's a little bit strange as every other item in sys.modules is a module.
msg327050 - (view) Author: miss-islington (miss-islington) Date: 2018-10-04 13:15
New changeset c57eb9a336391dc22aa29e9db592fa06d7fb7101 by Miss Islington (bot) (Chih-Hsuan Yen) in branch 'master':
bpo-34871: Fix two typos in test_inspect.py (GH-9698)
https://github.com/python/cpython/commit/c57eb9a336391dc22aa29e9db592fa06d7fb7101
msg327066 - (view) Author: miss-islington (miss-islington) Date: 2018-10-04 16:47
New changeset 6f85b826b527e240551613aeec3118a5469e3a33 by Miss Islington (bot) (INADA Naoki) in branch 'master':
bpo-34871: inspect: Don't pollute sys.modules (GH-9696)
https://github.com/python/cpython/commit/6f85b826b527e240551613aeec3118a5469e3a33
msg327075 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-04 19:26
New changeset 70a083bc46aea84e3b3ffca2c10c295917a98fec by Yury Selivanov (Miss Islington (bot)) in branch '3.6':
bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (GH-9702)
https://github.com/python/cpython/commit/70a083bc46aea84e3b3ffca2c10c295917a98fec
msg327076 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-04 19:26
New changeset 476c294f260ebe1b44157a168c3dfa4a43724ce3 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (#9701)
https://github.com/python/cpython/commit/476c294f260ebe1b44157a168c3dfa4a43724ce3
msg327077 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-10-04 19:34
Thank you Inada-san for taking care of this.
History
Date User Action Args
2018-10-04 19:34:39yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg327077

stage: patch review -> resolved
2018-10-04 19:26:37yselivanovsetmessages: + msg327076
2018-10-04 19:26:34yselivanovsetmessages: + msg327075
2018-10-04 16:47:35miss-islingtonsetpull_requests: + pull_request9087
2018-10-04 16:47:27miss-islingtonsetpull_requests: + pull_request9086
2018-10-04 16:47:14miss-islingtonsetmessages: + msg327066
2018-10-04 13:15:05miss-islingtonsetnosy: + miss-islington
messages: + msg327050
2018-10-04 12:57:43yan12125setpull_requests: + pull_request9084
2018-10-04 09:42:07inada.naokisetkeywords: + patch
stage: patch review
pull_requests: + pull_request9083
2018-10-02 17:44:27serhiy.storchakasetnosy: + yselivanov
2018-10-02 16:05:35yan12125setmessages: + msg326885
2018-10-02 14:57:03xtreaksetnosy: + inada.naoki
messages: + msg326884
2018-10-02 14:47:12xtreaksetnosy: + xtreak
2018-10-02 14:39:01vstinnersetnosy: + vstinner
messages: + msg326882
2018-10-02 14:37:42yan12125create