STY: use pytest.raises context syntax
State: closed

There are still about a thousand non-context usages of pytest.raises.

@gfyoung if there is a subset of these that especially merit match kwargs, let me know.  I'm not eager to manually go through all of them, but doing something systematic or manually doing a few I'd be up for.

Labels:
name: Code Style
description: Code style, linting, code_checks

Comments:
Hello @jbrockmendel! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/tests/api/test_types.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/api/test_types.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/categorical/test_api.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/arrays/categorical/test_api.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/categorical/test_constructors.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/arrays/categorical/test_constructors.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/categorical/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/arrays/categorical/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/arrays/categorical/test_operators.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/arrays/categorical/test_operators.py) !

 - There are no PEP8 issues in the file [`pandas/tests/frame/test_apply.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/frame/test_apply.py) !

 - There are no PEP8 issues in the file [`pandas/tests/frame/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/frame/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/frame/test_quantile.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/frame/test_quantile.py) !

 - There are no PEP8 issues in the file [`pandas/tests/generic/test_frame.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/generic/test_frame.py) !

 - There are no PEP8 issues in the file [`pandas/tests/groupby/test_categorical.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/groupby/test_categorical.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/datetimes/test_astype.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexes/datetimes/test_astype.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/multi/test_analytics.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexes/multi/test_analytics.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexes/multi/test_sorting.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexes/multi/test_sorting.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexing/multiindex/test_setitem.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexing/multiindex/test_setitem.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexing/multiindex/test_slice.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexing/multiindex/test_slice.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexing/test_indexing.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexing/test_indexing.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexing/test_panel.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexing/test_panel.py) !

 - There are no PEP8 issues in the file [`pandas/tests/indexing/test_partial.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/indexing/test_partial.py) !

 - There are no PEP8 issues in the file [`pandas/tests/resample/test_resample_api.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/resample/test_resample_api.py) !

 - There are no PEP8 issues in the file [`pandas/tests/reshape/merge/test_multi.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/reshape/merge/test_multi.py) !

 - There are no PEP8 issues in the file [`pandas/tests/series/indexing/test_boolean.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/series/indexing/test_boolean.py) !

 - There are no PEP8 issues in the file [`pandas/tests/series/indexing/test_numeric.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/series/indexing/test_numeric.py) !

 - There are no PEP8 issues in the file [`pandas/tests/series/test_apply.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/series/test_apply.py) !

 - There are no PEP8 issues in the file [`pandas/tests/test_base.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/test_base.py) !

 - There are no PEP8 issues in the file [`pandas/tests/test_lib.py`](https://github.com/jbrockmendel/pandas/blob/c8fa1bc8606e3ec43e46fac82e5e451c46ee3f59/pandas/tests/test_lib.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=h1) Report
> Merging [#24297](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/e3b6683a707c195ccc26a161587ab1b60706d0c4?src=pr&el=desc) will **decrease** coverage by `49.27%`.
> The diff coverage is `n/a`.

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

```diff
@@             Coverage Diff             @@
##           master   #24297       +/-   ##
===========================================
- Coverage   92.28%      43%   -49.28%     
===========================================
  Files         162      162               
  Lines       51830    51830               
===========================================
- Hits        47831    22290    -25541     
- Misses       3999    29540    +25541
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `43% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-98.65%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.15%)` | :arrow_down: |
| [pandas/core/tools/numeric.py](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvbnVtZXJpYy5weQ==) | `10.44% <0%> (-89.56%)` | :arrow_down: |
| ... and [120 more](https://codecov.io/gh/pandas-dev/pandas/pull/24297/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24297?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/24297?src=pr&el=footer). Last update [e3b6683...59cb98b](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=h1) Report
> Merging [#24297](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/df3b045e92ad139e1b22fce1cb2056c94430f6d5?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #24297   +/-   ##
=======================================
  Coverage   92.28%   92.28%           
=======================================
  Files         162      162           
  Lines       51827    51827           
=======================================
  Hits        47827    47827           
  Misses       4000     4000
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.68% <ø> (ø)` | :arrow_up: |
| #single | `43.01% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24297?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/24297?src=pr&el=footer). Last update [df3b045...b057554](https://codecov.io/gh/pandas-dev/pandas/pull/24297?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jbrockmendel : Thanks for the ping.  Given how massive this is, I think we can just focus on the conversion to context manager first.  Which ones should use a match parameter can be determined after (i.e. subsequent PR’s)
thanks. @gfyoung we should prob have a lint rule to detect this, but leave commented for now 
@jreback: I actually was discussing the checking if error messages, not the usage of the context manager versus not.  That being said, I do agree we should lint for what was addressed here.