def test_option_precedence_cmdline_over_ini(
    pytester: Pytester, ignore_on_cmdline
) -> None:
    """Filters defined in the command-line should take precedence over filters in ini files (#3946)."""
    pytester.makeini(
        """
        [pytest]
        filterwarnings = error::UserWarning
    """
    )
    pytester.makepyfile(
        """
        import warnings
        def test():
            warnings.warn(UserWarning('hello'))
    """
    )
    args = ["-W", "ignore"] if ignore_on_cmdline else []
    result = pytester.runpytest(*args)
    if ignore_on_cmdline:
        result.stdout.fnmatch_lines(["* 1 passed in*"])
    else:
        result.stdout.fnmatch_lines(["* 1 failed in*"])
Filters defined in the command-line should take precedence over filters in ini files (#3946).
testing/test_warnings.py