MAINT: tm.assert_raises_regex --> pytest.raises
`pytest.raises` has all of the functionality that we need from `tm.assert_raises_regex`.

Closes #16521 (for good this time! 🙂 ).

If this is something we would like to have for `0.24.0`, I would ask that this get reviewed and merged ASAP, given how massive the refactoring is and the high probability of merge conflicts.

cc @pandas-dev/pandas-core
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=h1) Report
> Merging [#23592](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/8ed92efc65b51a9010bd14e0e666fc722226e50a?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/23592/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #23592      +/-   ##
==========================================
- Coverage   92.25%   92.24%   -0.02%     
==========================================
  Files         161      161              
  Lines       51277    51278       +1     
==========================================
- Hits        47305    47299       -6     
- Misses       3972     3979       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.62% <100%> (-0.02%)` | :arrow_down: |
| #single | `42.28% <0%> (-0.04%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/23592/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `86.05% <100%> (-0.66%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=footer). Last update [8ed92ef...2b7fb24](https://codecov.io/gh/pandas-dev/pandas/pull/23592?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
 @gfyoung wasn't expecting all of these in a single PR. ok though. can you deprecate tm.assert_raises_regex as well. and update the docs. ping when ready > can you deprecate tm.assert_raises_regex as well. and update the docs.

Let's do that in a separate PR? This diff is already huge to check > Let's do that in a separate PR? This diff is already huge to check

yes this is ok `assert_raises_regex` is removed in this PR, I think it's the last file, you need to expand the diff, as it's collapsed because of the size. Then let's add it back here, if we want to deprecate it (which I think is a good idea) @jreback @jorisvandenbossche :

Why are we deprecating?  It's not even part of the public testing API (in `pandas/testing`).  There are no docs to update in the first place.

`assert_raises_regex` is essentially our internal implementation for doing what `pytest.raises` does now.
@datapythonista identified several places for refactorings and improvements, but I would like to save those for a follow-up.  From the viewpoint of infrastructure, this is ready to merge. the reason to deprecate is that it’s in our public ish testing interface and has been around for a while - we can just remove in the next version (short deprecation cycle)
this is a little more friendly  > the reason to deprecate is that it’s in our public ish testing interface and has been around for a while - we can just remove in the next version (short deprecation cycle)

@jreback : Okay, that's fair.  I'll deprecate this then and have it removed in the next major release (either `0.25` or `1.0`, given that this is not totally public, only "public-ish" 🙂 ). @jreback @datapythonista : Addressed all comments, and all is still green.  PTAL. thanks! didn’t check but do we fail an internal build if assert_raises_regex is used?

sure it would raise a FutureWarning but that doesn’t always fail it i think The numpydev job will fail if we use it in a test that is run, but that
doesn't have all the optional dependencies
so some tests are skipped.

On Sun, Nov 11, 2018 at 1:09 PM Jeff Reback <notifications@github.com>
wrote:

> didn’t check but do we fail an internal build if assert_raises_regex is
> used?
>
> sure it would raise a FutureWarning but that doesn’t always fail it i think
>
> —
> You are receiving this because you are on a team that was mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/23592#issuecomment-437696040>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIoM8fzT1P-JT--yvCcI9L5WQAksEks5uuHXdgaJpZM4YWP16>
> .
>
 ok @gfyoung can u add to the code_checks then to look for this (we already do for things like np.testing) @jreback @TomAugspurger : I grepped the entire codebase, and the only instances of `assert_raises_regex` are in `testing.py` and `test_testing.py`.

The warnings should cause the `numpydev` build to fail if it were to happen (which it doesn't). I think the idea is not on what we have now, but in case someone creates a new PR that uses `assert_raises_regex`. I can add the check, so we show the CI in red if that's the case. Will send a PR with it shortly. Opened #23627 with the check.