TST: Skip db tests unless explicitly specified in -m pattern
State: closed

- [x] closes #24485

Since #24450 we don't skip the db tests if the connection fails. That's useful, because the CI won't fail silently if there is any problem with the databases. But as reported in #24485, it's common to have `pymysql` or `psycopg2` installed locally, but no database connection. This is making the tests fail locally, and the agreed solution is to skip the db tests unless they are explicitly requested. 

But pytest doesn't make it easy to skip tests by default when using `-m`, but this solution should work. Another option would be an `--include-db` option, but I think it makes reading the expressions in the build very difficult (like, what `--only-slow --include-db` runs?). With `-m` the expressions are much clearer (e.g. `slow and db`), so I think this option is better.

The `eval` is how `pytest` itself evaluates the value of the `-m` parameter.


Labels:
name: Testing
description: pandas testing functions or related to the test suite

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24492?src=pr&el=h1) Report
> Merging [#24492](https://codecov.io/gh/pandas-dev/pandas/pull/24492?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/02a97c0a150377fab02fa22580d232c8242b5baa?src=pr&el=desc) will **decrease** coverage by `60.38%`.
> The diff coverage is `0%`.

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

```diff
@@             Coverage Diff             @@
##           master   #24492       +/-   ##
===========================================
- Coverage   92.31%   31.92%   -60.39%     
===========================================
  Files         166      166               
  Lines       52412    52412               
===========================================
- Hits        48382    16731    -31651     
- Misses       4030    35681    +31651
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `30.31% <0%> (-60.42%)` | :arrow_down: |
| #single | `31.92% <0%> (-11.14%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24492?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/util/\_tester.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3Rlci5weQ==) | `23.8% <0%> (ø)` | :arrow_up: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/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/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/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/24492/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/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `8.06% <0%> (-91.51%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| ... and [126 more](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24492?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/24492?src=pr&el=footer). Last update [02a97c0...e918cc8](https://codecov.io/gh/pandas-dev/pandas/pull/24492?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/24492?src=pr&el=h1) Report
> Merging [#24492](https://codecov.io/gh/pandas-dev/pandas/pull/24492?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/36ab8c95a41bbadc286a5a520883b149c86931bd?src=pr&el=desc) will **decrease** coverage by `60.4%`.
> The diff coverage is `0%`.

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

```diff
@@             Coverage Diff             @@
##           master   #24492       +/-   ##
===========================================
- Coverage   92.31%   31.91%   -60.41%     
===========================================
  Files         166      166               
  Lines       52387    52387               
===========================================
- Hits        48359    16717    -31642     
- Misses       4028    35670    +31642
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `30.3% <0%> (-60.43%)` | :arrow_down: |
| #single | `31.91% <0%> (-11.14%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24492?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/util/\_tester.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3Rlci5weQ==) | `23.8% <0%> (ø)` | :arrow_up: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/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/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/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/24492/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/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `8.06% <0%> (-91.51%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| ... and [126 more](https://codecov.io/gh/pandas-dev/pandas/pull/24492/diff?src=pr&el=tree-more) | |

------

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

> but I think it makes reading the expressions in the build very difficult (like, what `--only-slow --include-db` runs?)

@datapythonista : I'm confused by the motivation for your changes here...

Where have we defined a flag for `--include-db` ?
good point @gfyoung, I added much more context and references to the previous issues to the description. I think it should be clear now, let me know if it's not.
lgtm. merge on green.
thanks!