Remove bare exceptions from 'pandas/tests' to decrease flake8 E722 warnings
State: closed

Closes #22872

In my experience, the main reson to not catch bare exception is that thet progam has no way of using distinguisging keyboard exception (`crtl + C`) from regular exception. So I opted for 

```python
except Exception:
```

in cases where it's not clear what exception may happen or function wrapped in a try-except is so large that basically any exception can in different situations happen.

- [x] closes #xxxx
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas
name: Clean

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

 - There are no PEP8 issues in the file [`pandas/tests/indexing/common.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/indexing/common.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/formats/test_format.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/io/formats/test_format.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_pytables.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/io/test_pytables.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_sql.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/io/test_sql.py) !

 - There are no PEP8 issues in the file [`pandas/tests/test_multilevel.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/test_multilevel.py) !

 - There are no PEP8 issues in the file [`pandas/tests/test_nanops.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/test_nanops.py) !

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

 - There are no PEP8 issues in the file [`pandas/tests/test_strings.py`](https://github.com/HaraldNordgren/pandas/blob/4f7a7e6d9402b493f754f2909228599573180163/pandas/tests/test_strings.py) !


# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22882?src=pr&el=h1) Report
> Merging [#22882](https://codecov.io/gh/pandas-dev/pandas/pull/22882?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/f4fae353eaaa719db335ec2b21259932de30f46d?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/22882/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22882?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #22882   +/-   ##
=======================================
  Coverage   92.18%   92.18%           
=======================================
  Files         169      169           
  Lines       50830    50830           
=======================================
  Hits        46860    46860           
  Misses       3970     3970
```

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


------

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

@WillAyd Added some more specific errors. Do you think it looks better or would you like to go deeper?

In cases like https://github.com/pandas-dev/pandas/pull/22882/files#diff-45436d9cd11edcc7297e0dc3d699a328R217 I'm not sure which exceptions to catch? E.g. When changing it to `(KeyError, AttributeError)` the tests fail.
@HaraldNordgren I still think it's worthwhile to go deeper. 

What failures are you getting in your aforementioned example? Are the errors not clueing you in further on what exceptions to catch?
@HaraldNordgren can you make the requested fixes?
can you merge master and update
I think this is fixing the same problems than #23370, which is ready to be merged. Closing as duplicate.