def test_setup_teardown_function_level_with_optional_argument(
    pytester: Pytester,
    monkeypatch,
    arg: str,
) -> None:
    """Parameter to setup/teardown xunit-style functions parameter is now optional (#1728)."""
    import sys

    trace_setups_teardowns: list[str] = []
    monkeypatch.setattr(
        sys, "trace_setups_teardowns", trace_setups_teardowns, raising=False
    )
    p = pytester.makepyfile(
        f"""
        import pytest
        import sys

        trace = sys.trace_setups_teardowns.append

        def setup_module({arg}): trace('setup_module')
        def teardown_module({arg}): trace('teardown_module')

        def setup_function({arg}): trace('setup_function')
        def teardown_function({arg}): trace('teardown_function')

        def test_function_1(): pass
        def test_function_2(): pass

        class Test(object):
            def setup_method(self, {arg}): trace('setup_method')
            def teardown_method(self, {arg}): trace('teardown_method')

            def test_method_1(self): pass
            def test_method_2(self): pass
    """
    )
    result = pytester.inline_run(p)
    result.assertoutcome(passed=4)

    expected = [
        "setup_module",
        "setup_function",
        "teardown_function",
        "setup_function",
        "teardown_function",
        "setup_method",
        "teardown_method",
        "setup_method",
        "teardown_method",
        "teardown_module",
    ]
    assert trace_setups_teardowns == expected
Parameter to setup/teardown xunit-style functions parameter is now optional (#1728).
testing/test_runner_xunit.py