Skip to content

Tests fail with Python 3.14 when invoked via python -m pytest ..., due to argparse changes #1284

@mgorny

Description

@mgorny

From What's New:

The default value of the program name for argparse.ArgumentParser now reflects the way the Python interpreter was instructed to find the main module code. (Contributed by Serhiy Storchaka and Alyssa Coghlan in gh-66436.)

As a result, when the test suite is invoked via python -m pytest, there's a number of test failures due to different argparse output. For example:

$ python -m pytest -x
========================================================= test session starts =========================================================
platform linux -- Python 3.14.0b1, pytest-8.3.5, pluggy-1.6.0
rootdir: /tmp/csvkit
plugins: cov-6.1.1
collected 346 items                                                                                                                   

tests/test_cleanup.py ..                                                                                                        [  0%]
tests/test_cli.py ......                                                                                                        [  2%]
tests/test_convert/test_convert.py ........                                                                                     [  4%]
tests/test_convert/test_fixed.py ........                                                                                       [  6%]
tests/test_grep.py ...........                                                                                                  [ 10%]
tests/test_utilities/test_csvclean.py ..................F

============================================================== FAILURES ===============================================================
______________________________________________________ TestCSVClean.test_options ______________________________________________________

self = <tests.test_utilities.test_csvclean.TestCSVClean testMethod=test_options>

    def test_options(self):
        for args, message in (
            (
                [],
                'No checks or fixes were enabled. See available options with: csvclean --help',
            ),
            (
                ['--join-short-rows', '--fill-short-rows'],
                'The --join-short-rows and --fill-short-rows options are mutually exclusive.',
            ),
        ):
            with self.subTest(args=args):
>               self.assertError(launch_new_instance, args, message)

tests/test_utilities/test_csvclean.py:62: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/utils.py:84: in assertError
    self.assertEqual(f.getvalue().splitlines()[-1], f'{command}: error: {message}')
E   AssertionError: 'python -m pytest: error: No checks or fix[56 chars]help' != 'csvclean: error: No checks or fixes were [48 chars]help'
E   - python -m pytest: error: No checks or fixes were enabled. See available options with: csvclean --help
E   ? ^^^^^ ----------
E   + csvclean: error: No checks or fixes were enabled. See available options with: csvclean --help
E   ? ^^^^^^^
========================================================== warnings summary ===========================================================
.venv/lib/python3.14/site-packages/pytimeparse/__init__.py:19
  /tmp/csvkit/.venv/lib/python3.14/site-packages/pytimeparse/__init__.py:19: DeprecationWarning: codecs.open() is deprecated. Use open() instead.
    with open(path.join(path.dirname(__file__), 'VERSION'),

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= short test summary info =======================================================
FAILED tests/test_utilities/test_csvclean.py::TestCSVClean::test_options - AssertionError: 'python -m pytest: error: No checks or fix[56 chars]help' != 'csvclean: error: No checks or fixes were [48 chars]h...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================== 1 failed, 53 passed, 1 warning in 0.61s ===============================================

The way I read the documentation, I think the right solution here is to pass the correct prog= when constructing ArgumentParser().

Reproduced with 62c855e.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions