Skip to content

argparse UserWarning after updating to pytest 9.0.0 #13910

@srittau

Description

@srittau

After updating pytest to 9.0.0, I get an UserWarning:

UserWarning: Do not expect file_or_dir in Namespace(keyword='', markexpr='', maxfail=0, confcutdir=None, noconftest=False, keepduplicates=False, collect_in_virtualenv=False, continue_on_collection_errors=False, importmode='prepend', basetemp=None, durations=None, durations_min=None, showfixtures=False, show_fixtures_per_test=False, version=0, plugins=[], disable_plugin_autoload=False, traceconfig=False, verbose=0, no_header=False, no_summary=False, fold_skipped=True, force_short_summary=False, reportchars='fE', disable_warnings=False, showlocals=False, tbstyle='auto', xfail_tb=False, showcapture='all', fulltrace=False, color='auto', code_highlight='yes', capture='fd', runxfail=False, pastebin=None, assertmode='rewrite', xmlpath=None, junitprefix=None, doctestmodules=False, doctestreport='udiff', doctestglob=[], doctest_ignore_import_errors=False, doctest_continue_on_failure=False, last_failed_no_failures='all', stepwise=False, stepwise_skip=False, stepwise_reset=False, logger_disable=[], markers=False, strict_config=None, strict_markers=None, strict=None, pythonwarnings=None, collectonly=False, pyargs=False, ignore=None, ignore_glob=None, deselect=None, inifilename=None, rootdir=None, help=False, debug=None, override_ini=None, usepdb=False, usepdb_cls=None, trace=False, lf=False, failedfirst=False, newfirst=False, cacheshow=None, cacheclear=False, setuponly=False, setupshow=False, setupplan=False, log_level=None, log_format=None, log_date_format=None, log_cli_level=None, log_cli_format=None, log_cli_date_format=None, log_file=None, log_file_mode=None, log_file_level=None, log_file_format=None, log_file_date_format=None, log_auto_indent=None, file_or_dir=[])

Here is the full traceback:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pytest/__main__.py", line 9, in <module>
    raise SystemExit(pytest.console_main())
                     ^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 221, in console_main
    code = main()
           ^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 191, in main
    config = _prepareconfig(new_args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 358, in _prepareconfig
    config: Config = pluginmanager.hook.pytest_cmdline_parse(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 167, in _multicall
    raise exception
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/helpconfig.py", line 124, in pytest_cmdline_parse
    config = yield
             ^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1155, in pytest_cmdline_parse
    self.parse(args)
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1513, in parse
    self._parser.parse_known_args(args, namespace=self.known_args_namespace)
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/argparsing.py", line 158, in parse_known_args
    return self.parse_known_and_unknown_args(args, namespace=namespace)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/srittau/Projekte/eventstreamd/.venv/lib/python3.12/site-packages/_pytest/config/argparsing.py", line 183, in parse_known_and_unknown_args
    return self.optparser.parse_known_intermixed_args(strargs, namespace)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 2479, in parse_known_intermixed_args
    warn('Do not expect %s in %s' % (action.dest, namespace))
UserWarning: Do not expect file_or_dir in Namespace(keyword='', markexpr='', maxfail=0, confcutdir=None, noconftest=False, keepduplicates=False, collect_in_virtualenv=False, continue_on_collection_errors=False, importmode='prepend', basetemp=None, durations=None, durations_min=None, showfixtures=False, show_fixtures_per_test=False, version=0, plugins=[], disable_plugin_autoload=False, traceconfig=False, verbose=0, no_header=False, no_summary=False, fold_skipped=True, force_short_summary=False, reportchars='fE', disable_warnings=False, showlocals=False, tbstyle='auto', xfail_tb=False, showcapture='all', fulltrace=False, color='auto', code_highlight='yes', capture='fd', runxfail=False, pastebin=None, assertmode='rewrite', xmlpath=None, junitprefix=None, doctestmodules=False, doctestreport='udiff', doctestglob=[], doctest_ignore_import_errors=False, doctest_continue_on_failure=False, last_failed_no_failures='all', stepwise=False, stepwise_skip=False, stepwise_reset=False, logger_disable=[], markers=False, strict_config=None, strict_markers=None, strict=None, pythonwarnings=None, collectonly=False, pyargs=False, ignore=None, ignore_glob=None, deselect=None, inifilename=None, rootdir=None, help=False, debug=None, override_ini=None, usepdb=False, usepdb_cls=None, trace=False, lf=False, failedfirst=False, newfirst=False, cacheshow=None, cacheclear=False, setuponly=False, setupshow=False, setupplan=False, log_level=None, log_format=None, log_date_format=None, log_cli_level=None, log_cli_format=None, log_cli_date_format=None, log_file=None, log_file_mode=None, log_file_level=None, log_file_format=None, log_file_date_format=None, log_auto_indent=None, file_or_dir=[])

This happens since updating pytest from 8.4.2 to 9.0.0, using Python 3.12.3.

Configuration is minimal:

[tool.pytest.ini_options]
python_files = ["evtstrd_test/*.py"]

Here is the project in question: https://github.com/srittau/eventstreamd/

pip list output:

Package           Version        Editable project location
----------------- -------------- -----------------------------------
asserts           0.13.1
eventstreamd      2025.10.1.dev0 /home/srittau/Projekte/eventstreamd
iniconfig         2.1.0
json-get          1.1.1
mypy              1.18.2
mypy_extensions   1.1.0
packaging         25.0
pastel            0.2.1
pathspec          0.12.1
pip               24.0
pluggy            1.6.0
poethepoet        0.37.0
Pygments          2.19.2
pytest            9.0.0
PyYAML            6.0.2
ruff              0.14.3
typing_extensions 4.15.0

Edit: The project in question uses argparse itself, but the bug also appear when commenting out the argparse import and all code using it. It also requires python -W error -m pytest to trigger the exception. Using pytest -W error won't trigger it, suggesting to me that it's not a problem in my tests, but in pytest itself.

Metadata

Metadata

Assignees

Labels

topic: configrelated to config handling, argument parsing and config filetype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions