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 — warnings.filters was modified by test_check_c_globals · Issue #95349 · python/cpython

warnings.filters was modified by test_check_c_globals #95349

New issue
Copy link
New issue
Copy link
Closed
Closed
warnings.filters was modified by test_check_c_globals#95349
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dir

Description

@zooba
zooba
opened on Jul 27, 2022
Issue body actions

When I run my own automated tests against main, I get the following test failure on macOS and Ubuntu.

Warning -- warnings.filters was modified by test_check_c_globals
Warning --   Before: (4544233792, [('error', None, <class 'BytesWarning'>, None, 0), ('default', None, <class 'Warning'>, None, 0), ('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], [('error', None, <class 'BytesWarning'>, None, 0), ('default', None, <class 'Warning'>, None, 0), ('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)])
Warning --   After:  (4544233792, [('error', None, <class 'BytesWarning'>, None, 0), ('default', None, <class 'Warning'>, None, 0), ('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0)], [('error', None, <class 'BytesWarning'>, None, 0), ('default', None, <class 'Warning'>, None, 0), ('default', None, <class 'DeprecationWarning'>, '__main__', 0), ('ignore', None, <class 'DeprecationWarning'>, None, 0), ('ignore', None, <class 'PendingDeprecationWarning'>, None, 0), ('ignore', None, <class 'ImportWarning'>, None, 0), ('ignore', None, <class 'ResourceWarning'>, None, 0), ('ignore', None, <class 'pkg_resources.PEP440Warning'>, None, 0)])

We've previously added code to preserve warnings.filters around tests that import pkg_resources it seems. I'm not entirely sure where it's coming from in this case, as it doesn't repro on Windows (or apparently on our buildbots), but I guess we need the same preservation around it.

@ericsnowcurrently I think this may be yours?

Activity

  1. zooba
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    on Jul 27, 2022
  2. ericsnowcurrently commented on Jul 27, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Jul 27, 2022
    Member
    More actions

    I'll take a look.

  3. zooba commented on Jul 28, 2022

    @zooba
    zooba
    on Jul 28, 2022
    MemberAuthor
    More actions

    I patched my own copy to have this as the test:

        def test_check_c_globals(self):
            with save_restore_warnings_filters():
                with test.test_tools.imports_under_tool('c-analyzer'):
                    from cpython.__main__ import main
                try:
                    main('check', {})
                except NotImplementedError:
                    raise unittest.SkipTest('not supported on this host')
    

    Solves the changed global, but I only assume the test is still valid.

  4. ericsnowcurrently commented on Aug 1, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 1, 2022
    Member
    More actions

    Sorry for the delay. I'll try to take a look today.

    Reacted by Steve Dower
  5. ericsnowcurrently commented on Aug 1, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 1, 2022
    Member
    More actions

    Hmm, that test is disabled and the code doesn't look like yours. Are you based on some other branch?

    https://github.com/python/cpython/blob/main/Lib/test/test_check_c_globals.py#L14-L19

  6. zooba commented on Aug 1, 2022

    @zooba
    zooba
    on Aug 1, 2022
    MemberAuthor
    More actions

    Yeah, I didn't merge any changes. It's just in my internal fork.

    The test may be disabled, but the import still happens, and that's apparently what leaks the change.

  7. ericsnowcurrently commented on Aug 1, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 1, 2022
    Member
    More actions

    I'm unclear on why test_check_c_globals would be causing this problem. Neither it nor anything in Tools/c-analyzer messes with warnings. Perhaps it is something with test_tools? (I'm using a couple helpers from there.)

    Is this a new failure?

    FWIW, I don't get a failure when I run the test locally. How are you invoking the tests?

  8. zooba commented on Aug 1, 2022

    @zooba
    zooba
    on Aug 1, 2022
    MemberAuthor
    More actions

    I think it's something in the c-analyzer tool triggering it. Considering the warning being filtered is from pkgutil, it might be loading distutils/setuptools or pip? But once I remove the import from the test module, it doesn't trigger anymore.

    Maybe you've got something else in your environment that loads this stuff earlier? So then it doesn't look like the test is adding the extra warning filter because it's already there?

    I'm basically just running normal CI, it's just not on GitHub Actions.

  9. zooba commented on Aug 1, 2022

    @zooba
    zooba
    on Aug 1, 2022
    MemberAuthor
    More actions

    No, it's not quite normal. I configure with custom --prefix and make install before doing make buildbottest, so I'm not sure how different that makes things.

  10. ericsnowcurrently commented on Aug 3, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 3, 2022
    Member
    More actions

    I think it's something in the c-analyzer tool triggering it. Considering the warning being filtered is from pkgutil, it might be loading distutils/setuptools or pip? But once I remove the import from the test module, it doesn't trigger anymore.

    Yeah, I suspect this is a consequence of PEP 632 and the fact that we're still using parts of distutils in the c-analyzer (or at least were until 11 days ago).

    Do you still see the problem with the latest main?

    Regardless, I don't mind adding the fix you suggested if needed.

    Maybe you've got something else in your environment that loads this stuff earlier? So then it doesn't look like the test is adding the extra warning filter because it's already there?

    I bet that's it.

  11. zooba commented on Aug 3, 2022

    @zooba
    zooba
    on Aug 3, 2022
    MemberAuthor
    More actions

    Do you still see the problem with the latest main?

    My build from 7 hours ago failed in the same way. I wouldn't have thought it was coming from distutils though, unless it's coming from the distutils test suite?

  12. ericsnowcurrently commented on Aug 9, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 9, 2022
    Member
    More actions

    FYI, here's what I see:

    $ ./python -m test test_check_c_globals
    0:00:00 load avg: 0.15 Run tests sequentially
    0:00:00 load avg: 0.15 [1/1] test_check_c_globals
    $CPYTHON_ROOOT/Tools/c-analyzer/c_parser/preprocessor/common.py:2: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
      import distutils.ccompiler
    
    == Tests result: SUCCESS ==
    
    1 test OK.
    
    Total duration: 278 ms
    Tests result: SUCCESS
    

    I do get the warning but it doesn't cause a failure.

  13. ericsnowcurrently commented on Aug 9, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 9, 2022
    Member
    More actions

    I was able to reproduce the failure you originally described with an out-of-tree build and a custom --prefix:

    mkdir ../build
    cd ../build
    ../cpython/configure --cache-file=../python-config.cache --enable-ipv6 --prefix=$HOME/build/installed CFLAGS=-O0 --with-system-expat --with-system-ffi --with-pydebug
    make -j8
    make install
    ./python -E ../cpython/Tools/scripts/run_tests.py -j 1 -u all -W --slowest --fail-env-changed --timeout=1200  test_check_c_globals
    
  14. ericsnowcurrently commented on Aug 9, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 9, 2022
    Member
    More actions

    There's a comment in the distutils test that explains the situation:

    cpython/Lib/distutils/tests/__init__.py

    Lines 30 to 34 in 63140b4

    # bpo-40055: Save/restore warnings filters to leave them unchanged.
    # Importing tests imports docutils which imports pkg_resources
    # which adds a warnings filter.
    with save_restore_warnings_filters():
    __import__(modname)

  15. ericsnowcurrently commented on Aug 9, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 9, 2022
    Member
    More actions

    The referenced issue, gh-84236 (AKA bpo-40055) is basically the same as this one. Looks like here it's only happening with the specific build steps.

  16. ericsnowcurrently commented on Aug 9, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 9, 2022
    Member
    More actions

    My fix (gh-95837) should be good enough until we stop using distutils in the c-analyzer.

    Reacted by Steve Dower
  17. miss-islington
    added 2 commits that reference this issue on Aug 9, 2022

    gh-95349: Hide a Distutils Warning Filter for test_check_c_globals (G…

    3ff6d9a

    pythongh-95349: Hide a Distutils Warning Filter for test_check_c_glob…

    eea836c
  18. ambv
    added a commit that references this issue on Aug 10, 2022

    gh-95349: Hide a Distutils Warning Filter for test_check_c_globals (G…

    2c4bd21
  19. ericsnowcurrently commented on Aug 10, 2022

    @ericsnowcurrently
    ericsnowcurrently
    on Aug 10, 2022
    Member
    More actions

    Thanks for pointing this out, @zooba. It should be all fixed now. Would you mind verifying?

  20. zooba commented on Aug 10, 2022

    @zooba
    zooba
    on Aug 10, 2022
    MemberAuthor
    More actions

    It looks good in my build overnight 👍

    Reacted by Eric Snow
  21. zooba
    closed this as completedon Aug 10, 2022
  22. miss-islington
    added 2 commits that reference this issue on Aug 10, 2022

    pythongh-95349: Hide a Distutils Warning Filter for test_check_c_glob…

    0d7ed30

    gh-95349: Hide a Distutils Warning Filter for test_check_c_globals (G…

    b11895e
  23. iritkatriel
    added a commit that references this issue on Aug 11, 2022

    pythongh-95349: Hide a Distutils Warning Filter for test_check_c_glob…

    9f5868c
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 dir

    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.