Skip to content

Fix strict options from addopts#14443

Open
praneethhere wants to merge 1 commit intopytest-dev:mainfrom
praneethhere:fix-strict-options-from-addopts
Open

Fix strict options from addopts#14443
praneethhere wants to merge 1 commit intopytest-dev:mainfrom
praneethhere:fix-strict-options-from-addopts

Conversation

@praneethhere
Copy link
Copy Markdown

Closes #14442

This fixes a pytest 9 regression where --strict-markers and
--strict-config were ignored when configured through addopts

addopts is parsed after the initial config discovery step, so the
OverrideIniAction compatibility path updated the parsed argparse namespace,
but the generated ini overrides were not applied back into _inicfg

As a result, later getini() calls still saw the default values for
strict_markers and strict_config

This change applies parsed ini overrides after parsing the full argument list
including addopts, and clears the ini cache so later getini() calls use the
updated values

Added regression coverage for:

  • --strict-config from addopts
  • --strict-markers from addopts

Tested with:

python -m pytest -q \
  testing/test_config.py::TestParseIni::test_strict_config_from_addopts \
  testing/test_mark.py::test_strict_markers_from_addopts

python -m pytest -q \
  testing/test_config.py::TestParseIni::test_invalid_config_options \
  testing/test_mark.py::test_strict_prohibits_unregistered_markers

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label May 6, 2026
Copy link
Copy Markdown
Member

@The-Compiler The-Compiler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I can't comment much about the approach you took here (I'd like to defer that to e.g. @bluetech), but I added two suggestions.

Comment thread src/_pytest/config/__init__.py Outdated
)

self._inicfg.update(parse_override_ini(self.known_args_namespace.override_ini))
self._inicache.clear()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why run this a second time here? I don't see how pytest_addoption could somehow influence addopts.

If this is needed, can you please add a test to demonstrate that?

Comment thread testing/test_mark.py Outdated
result.stdout.fnmatch_lines(
["'unregisteredmark' not found in `markers` configuration option"]
)
assert result.ret != pytest.ExitCode.OK
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest matching on the actual return value, like in the other test you added.

@The-Compiler The-Compiler added the backport 9.0.x apply to PRs at any point; backports the changes to the 9.0.x branch label May 6, 2026
@The-Compiler The-Compiler requested a review from bluetech May 6, 2026 06:55
@praneethhere praneethhere force-pushed the fix-strict-options-from-addopts branch from d18dd84 to 3ce8f74 Compare May 6, 2026 07:17
@praneethhere
Copy link
Copy Markdown
Author

@The-Compiler Thanks for the review

I originally added the second _inicfg update as a defensive follow up after the later argument parse, in case any parsed overrides changed at that point. After looking at this again, it is not needed for this regression. The important path is the first parse after addopts has been included, before the strict config and marker handling reads from getini()

I removed the second update to keep the change scoped to the failing case

Also updated marker regression test to assert the exact exit code

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

Labels

backport 9.0.x apply to PRs at any point; backports the changes to the 9.0.x branch bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--strict-markers / --strict-config via addopts silently stopped working (pytest 9 regression)

2 participants