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

test_site fails if run after test_inspect #79052

Closed
yan12125 mannequin opened this issue Oct 2, 2018 · 9 comments
Closed

test_site fails if run after test_inspect #79052

yan12125 mannequin opened this issue Oct 2, 2018 · 9 comments
Labels
3.8 (EOL) end of life tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@yan12125
Copy link
Mannequin

yan12125 mannequin commented Oct 2, 2018

BPO 34871
Nosy @vstinner, @methane, @1st1, @yan12125, @miss-islington, @tirkarthi
PRs
  • bpo-34871: inspect: Don't pollute sys.modules #9696
  • bpo-34871: Fix two typos in test_inspect.py #9698
  • [3.7] bpo-34871: inspect: Don't pollute sys.modules (GH-9696) #9701
  • [3.6] bpo-34871: inspect: Don't pollute sys.modules (GH-9696) #9702
  • Files
  • cpython-failure.txt: Output of ./python -m test.regrtest -v test_inspect test_site
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-10-04.19:34:39.824>
    created_at = <Date 2018-10-02.14:37:42.865>
    labels = ['3.8', 'type-bug', 'tests']
    title = 'test_site fails if run after test_inspect'
    updated_at = <Date 2018-10-04.19:34:39.822>
    user = 'https://github.com/yan12125'

    bugs.python.org fields:

    activity = <Date 2018-10-04.19:34:39.822>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-04.19:34:39.824>
    closer = 'yselivanov'
    components = ['Tests']
    creation = <Date 2018-10-02.14:37:42.865>
    creator = 'yan12125'
    dependencies = []
    files = ['47842']
    hgrepos = []
    issue_num = 34871
    keywords = ['patch']
    message_count = 9.0
    messages = ['326881', '326882', '326884', '326885', '327050', '327066', '327075', '327076', '327077']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'methane', 'yselivanov', 'yan12125', 'miss-islington', 'xtreak']
    pr_nums = ['9696', '9698', '9701', '9702']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34871'
    versions = ['Python 3.8']

    @yan12125
    Copy link
    Mannequin Author

    yan12125 mannequin commented Oct 2, 2018

    $ ./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 81574b8, configured with ./configure

    @yan12125 yan12125 mannequin added 3.8 (EOL) end of life tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Oct 2, 2018
    @vstinner
    Copy link
    Member

    vstinner commented Oct 2, 2018

    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

    @tirkarthi
    Copy link
    Member

    The failing test was added with d4c76d9

    commit d4c76d9
    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 d4c76d9~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

    @yan12125
    Copy link
    Mannequin Author

    yan12125 mannequin commented Oct 2, 2018

    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.

    @miss-islington
    Copy link
    Contributor

    New changeset c57eb9a by Miss Islington (bot) (Chih-Hsuan Yen) in branch 'master':
    bpo-34871: Fix two typos in test_inspect.py (GH-9698)
    c57eb9a

    @miss-islington
    Copy link
    Contributor

    New changeset 6f85b82 by Miss Islington (bot) (INADA Naoki) in branch 'master':
    bpo-34871: inspect: Don't pollute sys.modules (GH-9696)
    6f85b82

    @1st1
    Copy link
    Member

    1st1 commented Oct 4, 2018

    New changeset 70a083b by Yury Selivanov (Miss Islington (bot)) in branch '3.6':
    bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (GH-9702)
    70a083b

    @1st1
    Copy link
    Member

    1st1 commented Oct 4, 2018

    New changeset 476c294 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
    bpo-34871: inspect: Don't pollute sys.modules (GH-9696) (bpo-9701)
    476c294

    @1st1
    Copy link
    Member

    1st1 commented Oct 4, 2018

    Thank you Inada-san for taking care of this.

    @1st1 1st1 closed this as completed Oct 4, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants