TST: test for warnings using pytest.warns()
Fix tests that used `pytest.raises()` to check for warnings, to use `pytest.warns()` instead.  This is more correct, and it fixes running the test suite without `-Werror`.  This is how Gentoo runs it, to avoid sudden test failures due to new deprecation warnings from upgraded dependencies.

- [ ] closes #56716 (Replace xxxx with the GitHub issue number)
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

pre-commit.ci autofix Thanks @mgorny  Thanks! And sorry for not running pre-commit in the morning, as I've updated the PR just before going out.