How to expect a specific exception with Pytest's xfail?

Use @pytest.xfail with the raises param.

from pytest import mark

@mark.xfail(raises=RuntimeError)
def test_func() -> None:
    func()

While this lets you expect a specific exception, it won’t let you say where it should happen in the test.