Skip to content

tests/test_integration.py::test_prog fails with Python 3.14 when starting via python -m pytest #239

Description

@mgorny

Summary

Python 3.14 changed the way the default prog= value is computed. When the program is run via python -m ..., it uses that value rather than argv[0]. As a result, when tests are run via python -m pytest, I'm getting the following failure:

$ python -m pytest 
========================================================= test session starts =========================================================
platform linux -- Python 3.14.0b2, pytest-8.3.5, pluggy-1.6.0
rootdir: /tmp/argh
configfile: pyproject.toml
plugins: cov-6.1.1
collected 170 items                                                                                                                   

tests/test_assembling.py ......................................                                                                 [ 22%]
tests/test_completion.py ...                                                                                                    [ 24%]
tests/test_decorators.py ......                                                                                                 [ 27%]
tests/test_dispatching.py ........                                                                                              [ 32%]
tests/test_dto.py ....                                                                                                          [ 34%]
tests/test_integration.py ...........................................F...........                                               [ 67%]
tests/test_interaction.py .....                                                                                                 [ 70%]
tests/test_mapping_policies.py ..........................                                                                       [ 85%]
tests/test_regressions.py .............                                                                                         [ 92%]
tests/test_typing_hints.py ........                                                                                             [ 97%]
tests/test_utils.py ....                                                                                                        [100%]

============================================================== FAILURES ===============================================================
______________________________________________________________ test_prog ______________________________________________________________

capsys = <_pytest.capture.CaptureFixture object at 0x7fa524b72ba0>

    def test_prog(capsys: pytest.CaptureFixture[str]):
        "Program name propagates from sys.argv[0]"
    
        def cmd(*, foo=1):
            return foo
    
        parser = DebugArghParser()
        parser.add_commands([cmd])
    
        usage = get_usage_string()
    
        assert run(parser, "-h", exit=True) == 0
        captured = capsys.readouterr()
>       assert captured.out.startswith(usage)
E       AssertionError: assert False
E        +  where False = <built-in method startswith of str object at 0x7fa524aa3cb0>('usage: __main__.py [-h] {cmd} ...\n\n')
E        +    where <built-in method startswith of str object at 0x7fa524aa3cb0> = 'usage: python -m pytest [-h] {cmd} ...\n\npositional arguments:\n  {cmd}\n    cmd\n\noptions:\n  -h, --help  show this help message and exit\n'.startswith
E        +      where 'usage: python -m pytest [-h] {cmd} ...\n\npositional arguments:\n  {cmd}\n    cmd\n\noptions:\n  -h, --help  show this help message and exit\n' = CaptureResult(out='usage: python -m pytest [-h] {cmd} ...\n\npositional arguments:\n  {cmd}\n    cmd\n\noptions:\n  -h, --help  show this help message and exit\n', err='').out

tests/test_integration.py:815: AssertionError
========================================================== warnings summary ===========================================================
tests/test_dispatching.py::test_dispatch_command_two_stage
  /tmp/argh/src/argh/dispatching.py:168: DeprecationWarning: The argument `namespace` in `dispatch()` is deprecated. It will be removed in the next minor version after v0.31.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= short test summary info =======================================================
FAILED tests/test_integration.py::test_prog - AssertionError: assert False
============================================== 1 failed, 169 passed, 1 warning in 0.32s ===============================================

To Reproduce

uv venv -p 3.14
uv pip install -e .[test]
.venv/bin/python -m pytest

Expected behavior

Tests passing.

Environment

  • OS: Gentoo Linux amd64
  • Python version: 3.14.0b2
  • Argh version: 8d25286

Activity

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions