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

configure warnings as errors in the test suite #128770

Open
graingert opened this issue Jan 13, 2025 · 4 comments
Open

configure warnings as errors in the test suite #128770

graingert opened this issue Jan 13, 2025 · 4 comments
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@graingert
Copy link
Contributor

graingert commented Jan 13, 2025

Feature or enhancement

Proposal:

It's very easy (especially when deprecating something) to introduce a lot of noisy test output with new warnings, eg: #127949 (comment)

I think it would be useful to either configure warnings as errors in the test suite (and then capture unraisable/threadexcept errors using a mechanism like pytest has) or tee any warnings produced, and fail CI if any have been produced that were not captured with catch_warnings or assertWarns etc like https://pypi.org/project/pytest-max-warnings/

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/its-too-easy-to-introduce-noise-in-cpythons-test-suite-output-resourcewarnings-and-deprecationwarnings/75234

Linked PRs

@sobolevn
Copy link
Member

See #110012 test_socket raises warnings right now.

@graingert
Copy link
Contributor Author

See #128816 test_doctest also has a warning

@graingert
Copy link
Contributor Author

See #110012 test_socket raises warnings right now.

I'm thinking we mark these as default with catch_warnings in the test for now?

hugovk pushed a commit that referenced this issue Jan 17, 2025
…ocket which still logs warnings (#128726)

Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 17, 2025
…test_socket which still logs warnings (pythonGH-128726)

(cherry picked from commit 7807b40)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
hugovk added a commit to hugovk/cpython that referenced this issue Jan 17, 2025
…ept for test_socket which still logs warnings (python#128726)"

This reverts commit 7807b40.
hugovk added a commit that referenced this issue Jan 17, 2025
graingert added a commit to graingert/cpython that referenced this issue Jan 18, 2025
…cept for test_socket which still logs warnings (python#128726)" (python#128936)

This reverts commit 76856ae.
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 21, 2025
…test_socket which still logs warnings (python#128726)

Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 21, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 22, 2025
(cherry picked from commit 24c84d8)

Co-authored-by: Thomas Grainger <[email protected]>
hugovk pushed a commit that referenced this issue Mar 27, 2025
…ocket which still logs warnings, and internal test warnings that are now logged (#128973)

Co-authored-by: Bénédikt Tran <[email protected]>
graingert added a commit to graingert/cpython that referenced this issue Mar 27, 2025
…test_socket which still logs warnings, and internal test warnings that are now logged (python#128973)

Co-authored-by: Bénédikt Tran <[email protected]>
(cherry picked from commit 8a00c9a)
hugovk pushed a commit that referenced this issue Mar 29, 2025
… test_socket which still logs warnings, and internal test warnings that are now logged (#131802)

Co-authored-by: Bénédikt Tran <[email protected]>
(cherry picked from commit 8a00c9a)
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 1, 2025
…test_socket which still logs warnings, and internal test warnings that are now logged (python#128973)

Co-authored-by: Bénédikt Tran <[email protected]>
@kulikjak
Copy link
Contributor

kulikjak commented Apr 9, 2025

Hi, after this change (specifically #131802), I am seeing the following errors when running test_peg_generator:

======================================================================
ERROR: test_with_stmt_with_paren (test.test_peg_generator.test_c_parser.TestCParser.test_with_stmt_with_paren)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/Python-3.13.3/Lib/test/test_peg_generator/test_c_parser.py", line 113, in setUp
    cmd = support.missing_compiler_executable()
  File "/build/Python-3.13.3/Lib/test/support/__init__.py", line 1916, in missing_compiler_executable
    if spawn.find_executable(cmd[0]) is None:
       ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib/python3.13/vendor-packages/setuptools/_distutils/spawn.py", line 87, in find_executable
    warnings.warn(
    ~~~~~~~~~~~~~^
        'Use shutil.which instead of find_executable', DeprecationWarning, stacklevel=2
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
DeprecationWarning: Use shutil.which instead of find_executable

I tried replacing spawn.find_executable with shutil.which as the warning suggests, but then I get a different distutils warning and test still fails:

======================================================================
ERROR: test_with_stmt_with_paren (test.test_peg_generator.test_c_parser.TestCParser.test_with_stmt_with_paren)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/Python-3.13.3/Lib/test/test_peg_generator/test_c_parser.py", line 395, in test_with_stmt_with_paren
    self.run_test(grammar_source, test_source)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/Python-3.13.3/Lib/test/test_peg_generator/test_c_parser.py", line 134, in run_test
    self.build_extension(grammar_source)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/build/Python-3.13.3/Lib/test/test_peg_generator/test_c_parser.py", line 131, in build_extension
    generate_parser_c_extension(grammar, Path('.'), library_dir=self.library_dir)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/Python-3.13.3/Tools/peg_generator/pegen/testutil.py", line 107, in generate_parser_c_extension
    compile_c_extension(
    ~~~~~~~~~~~~~~~~~~~^
        str(source),
        ^^^^^^^^^^^^
    ...<3 lines>...
        library_dir=library_dir,
        ^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/build/Python-3.13.3/Tools/peg_generator/pegen/build.py", line 98, in compile_c_extension
    from setuptools._distutils.dep_util import newer_group
  File "/usr/lib/python3.13/vendor-packages/setuptools/_distutils/dep_util.py", line 9, in __getattr__
    warnings.warn(
    ~~~~~~~~~~~~~^
        "dep_util is Deprecated. Use functions from setuptools instead.",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        DeprecationWarning,
        ^^^^^^^^^^^^^^^^^^^
        stacklevel=2,
        ^^^^^^^^^^^^^
    )
    ^
DeprecationWarning: dep_util is Deprecated. Use functions from setuptools instead.

This is with 3.13 only, which makes sense as that is the only one which we have setuptools for also installed.

I wonder what is different about my setup considering that nobody else reported this?

nascheme added a commit to nascheme/cpython that referenced this issue Apr 9, 2025
This is needed because unit tests are now run with "-W error" on the
command line in CI (pythonGH-128770).  We want to start with an empty list of
filters to avoid supurious errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants