GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_sys.test_intern() fails if run more than once in the same process · Issue #108963 · python/cpython

test_sys.test_intern() fails if run more than once in the same process #108963

New issue
Copy link
New issue
Copy link
Closed
Closed
test_sys.test_intern() fails if run more than once in the same process#108963
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@vstinner
vstinner
opened on Sep 5, 2023
Issue body actions

Bug report

Example:

$ ./python -m test test_sys test_sys -m test_intern -v
(...)
0:00:00 load avg: 1.60 Run tests sequentially
0:00:00 load avg: 1.60 [1/2] test_sys
test_intern (test.test_sys.SysModuleTest.test_intern) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
0:00:00 load avg: 1.60 [2/2] test_sys
test_intern (test.test_sys.SysModuleTest.test_intern) ... FAIL

======================================================================
FAIL: test_intern (test.test_sys.SysModuleTest.test_intern)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/python/3.12/Lib/test/test_sys.py", line 687, in test_intern
    self.assertTrue(sys.intern(s) is s)
AssertionError: False is not true

----------------------------------------------------------------------
(...)

Result: FAILURE

Linked PRs

  • gh-108963: using random to generate unique string in sys.intern test #109491
  • [3.12] gh-108963: using random to generate unique string in sys.intern test … #110216

Activity

  1. vstinner
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    testsTests in the Lib/test dirTests in the Lib/test dir
    on Sep 5, 2023
  2. vstinner commented on Sep 6, 2023

    @vstinner
    vstinner
    on Sep 6, 2023
    MemberAuthor
    More actions

    @serhiy-storchaka: Oh, that another victim of regrtest trying to be nice :-) test_sys pass when run multiple times in the same process using this change:

    diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py
    index 16ae04191d..249e331434 100644
    --- a/Lib/test/libregrtest/runtest.py
    +++ b/Lib/test/libregrtest/runtest.py
    @@ -436,7 +436,7 @@ def _load_run_test(result: TestResult, ns: Namespace) -> None:
         module_name = abs_module_name(result.test_name, ns.testdir)
     
         # Remove the module from sys.module to reload it if it was already imported
    -    sys.modules.pop(module_name, None)
    +    #sys.modules.pop(module_name, None)
     
         test_mod = importlib.import_module(module_name)
     
    

    The interesting part is that ./python -m test -R 3:3 test_sys doesn't fail since it doesn't remove the test module between two test iterations ;-)

  3. serhiy-storchaka commented on Sep 6, 2023

    @serhiy-storchaka
    serhiy-storchaka
    on Sep 6, 2023
    Member
    More actions

    For reference, the module level counter was added in aee3486 to prevent test_intern failing when it is rerun in verbose mode. But if the module is reloaded, the counter is reset.

    One of solutions is to use the random module. Possibility of collisions in negligible.

    Other solution -- use timer in the hope that the computer is not fast enough to finish the whole test several times in the time resolution unit.

    We can also try to use id()s of some objects (self, globals(), locals()), but there is greater chance that all of them are allocated at exactly same address after reloading the module.

    test_subinterp_intern_dynamically_allocated fails for the same reason.

  4. aisk commented on Sep 16, 2023

    @aisk
    aisk
    on Sep 16, 2023
    Member
    More actions

    Trying to change to using random.random() and it looks like it works well: #109491

    C:\cpython>python -m test test_sys test_sys
    Running Debug|x64 interpreter...
    0:00:00 Run 2 tests sequentially
    0:00:00 [1/2] test_sys
    0:00:04 [2/2] test_sys
    
    == Tests result: SUCCESS ==
    
    All 2 tests OK.
    
    Total duration: 8.9 sec
    Total tests: run=148 skipped=12
    Total test files: run=2/2
    Result: SUCCESS
    
  5. vstinner
    changed the title [-]sys.test_intern() fails if run more than once in the same process[/-] [+]test_sys.test_intern() fails if run more than once in the same process[/+] on Sep 18, 2023
  6. vstinner
    added
    needs backport to 3.12only security fixesonly security fixes
    and removed
    needs backport to 3.12only security fixesonly security fixes
    on Oct 2, 2023
  7. vstinner
    added a commit that references this issue on Oct 2, 2023

    gh-108963: using random to generate unique string in sys.intern test (#…

    44b1e4e
  8. vstinner
    closed this as completedon Oct 2, 2023
  9. vstinner
    added a commit that references this issue on Oct 2, 2023

    pythongh-108963: using random to generate unique string in sys.intern…

    52c001d
  10. Yhg1s
    added a commit that references this issue on Oct 2, 2023

    [3.12] gh-108963: using random to generate unique string in sys.inter…

    f911d7e
  11. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-108963: using random to generate unique string in sys.intern…

    34f3941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.