Could you please make the tests not rely on specific argv[0]? We're running tests on Gentoo via python -m pytest as that guarantees that the correct Python version/environment will be used, and this means argv[0] is __main__ rather than pytest.
========================================================= test session starts =========================================================
platform linux -- Python 3.10.10, pytest-7.2.1, pluggy-1.0.0
cachedir: .tox/py310/.pytest_cache
rootdir: /tmp/argh
plugins: cov-4.0.0
collected 102 items
tests/test_assembling.py ................... [ 18%]
tests/test_completion.py ... [ 21%]
tests/test_decorators.py ...... [ 27%]
tests/test_dispatching.py ... [ 30%]
tests/test_integration.py .......xxx......................................FFF [ 80%]
tests/test_interaction.py ..... [ 85%]
tests/test_regressions.py ....... [ 92%]
tests/test_utils.py ........ [100%]
============================================================== FAILURES ===============================================================
___________________________________________________ test_add_commands_no_overrides ____________________________________________________
def test_add_commands_no_overrides():
def first_func(foo=123):
"""Owl stretching time"""
pass
def second_func():
pass
p = argh.ArghParser()
p.add_commands(
[first_func, second_func],
)
with iocapture.capture() as captured:
run(p, "--help", exit=True)
> assert (
captured.stdout
== unindent(
f"""
usage: pytest [-h] {{first-func,second-func}} ...
positional arguments:
{{first-func,second-func}}
first-func Owl stretching time
second-func
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
"""
)[1:]
)
E AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
E - usage: pytest [-h] {first-func,second-func} ...
E ? ----
E + usage: __main__.py [-h] {first-func,second-func} ...
E ? +++++++++
E
E positional arguments:
E {first-func,second-func}...
E
E ...Full output truncated (6 lines hidden), use '-vv' to show
tests/test_integration.py:807: AssertionError
________________________________________________ test_add_commands_namespace_overrides ________________________________________________
def test_add_commands_namespace_overrides():
"""
When `namespace_kwargs` is passed to `add_commands()`, its members override
whatever was specified on function level.
"""
def first_func(foo=123):
"""Owl stretching time"""
pass
def second_func():
pass
p = argh.ArghParser()
p.add_commands(
[first_func, second_func],
namespace="ns",
namespace_kwargs={
"help": "namespace help override",
"description": "namespace description override",
},
)
with iocapture.capture() as captured:
run(p, "--help", exit=True)
> assert (
captured.stdout
== unindent(
f"""
usage: pytest [-h] {{ns}} ...
positional arguments:
{{ns}}
ns
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
"""
)[1:]
)
E AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
E - usage: pytest [-h] {ns} ...
E ? ----
E + usage: __main__.py [-h] {ns} ...
E ? +++++++++
E
E positional arguments:
E {ns}...
E
E ...Full output truncated (5 lines hidden), use '-vv' to show
tests/test_integration.py:867: AssertionError
__________________________________________________ test_add_commands_func_overrides ___________________________________________________
def test_add_commands_func_overrides():
"""
When `func_kwargs` is passed to `add_commands()`, its members override
whatever was specified on function level.
"""
def first_func(foo=123):
"""Owl stretching time"""
pass
def second_func():
pass
p = argh.ArghParser()
p.add_commands(
[first_func, second_func],
func_kwargs={
"help": "func help override",
"description": "func description override",
},
)
with iocapture.capture() as captured:
run(p, "--help", exit=True)
> assert (
captured.stdout
== unindent(
f"""
usage: pytest [-h] {{first-func,second-func}} ...
positional arguments:
{{first-func,second-func}}
first-func func help override
second-func func help override
{HELP_OPTIONS_LABEL}:
-h, --help show this help message and exit
"""
)[1:]
)
E AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
E - usage: pytest [-h] {first-func,second-func} ...
E ? ----
E + usage: __main__.py [-h] {first-func,second-func} ...
E ? +++++++++
E
E positional arguments:
E {first-func,second-func}...
E
E ...Full output truncated (6 lines hidden), use '-vv' to show
tests/test_integration.py:947: AssertionError
======================================================= short test summary info =======================================================
FAILED tests/test_integration.py::test_add_commands_no_overrides - AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
FAILED tests/test_integration.py::test_add_commands_namespace_overrides - AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
FAILED tests/test_integration.py::test_add_commands_func_overrides - AssertionError: assert 'usage: __mai...ge and exit\n' == 'usage: pytes...ge and exit\n'
=============================================== 3 failed, 96 passed, 3 xfailed in 0.59s ===============================================
Could you please make the tests not rely on specific
argv[0]
? We're running tests on Gentoo viapython -m pytest
as that guarantees that the correct Python version/environment will be used, and this meansargv[0]
is__main__
rather thanpytest
.