PKG/DEP: Make importable without pytest
State: closed

Closes https://github.com/pandas-dev/pandas/issues/16065

Edit: removed the top-level imports of pytest in pandas.util.testing

Labels:
name: Dependencies
description: Required and optional dependencies

Comments:
Actually, thinking more about this I probably prefer removing the line from panads.__init__ and have people import it separately

```
import pandas.testing as tm
```
Since `pytest` isn't actually needed for the api functions (`assert_frame_equal`, etc), maybe those could be defined in `pandas.testing`, then imported back into `pandas.util.testing`?

edit: actually this is lot less trivial than I was originally thinking, so maybe not a good idea
Looking at [testing.py](https://github.com/pandas-dev/pandas/blob/2f9c854c30385c29a905c0a9bf0b5009e99347e0/pandas/util/testing.py) again - almost every use `pytest` already has function level imports, so may be best to bite the bullet and do it for the few remaining cases?
> so may be best to bite the bullet and do it for the few remaining cases?

OK, let me give this a shot.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16088?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@2f9c854`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `66.66%`.

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

```diff
@@            Coverage Diff            @@
##             master   #16088   +/-   ##
=========================================
  Coverage          ?   90.84%           
=========================================
  Files             ?      159           
  Lines             ?    50780           
  Branches          ?        0           
=========================================
  Hits              ?    46132           
  Misses            ?     4648           
  Partials          ?        0
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.62% <66.66%> (?)` | |
| #single | `40.36% <50%> (?)` | |

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

------

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

Ok, not too bad at all. Hopefully this passes.

And here it is working without pytest, which is nice

```python
In [1]: import pandas as pd

In [2]: pd.testing.assert_series_equal(pd.Series([1]), pd.Series([2]))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-2-46d7e85da706> in <module>()
----> 1 pd.testing.assert_series_equal(pd.Series([1]), pd.Series([2]))

/Users/taugspurger/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/util/testing.py in assert_series_equal(left, right, check_dtype, check_index_type, check_series_type, check_less_precise, check_names, check_exact, check_datetimelike_compat, check_categorical, obj)
   1310                                        check_less_precise=check_less_precise,
   1311                                        check_dtype=check_dtype,
-> 1312                                        obj='{0}'.format(obj))
   1313
   1314     # metadata comparison

as/pandas/util/testing.pyx in pandas.util.libtesting.assert_almost_equal (pandas/util/testing.c:4156)()

as/pandas/util/testing.pyx in pandas.util.libtesting.assert_almost_equal (pandas/util/testing.c:3274)()

/Users/taugspurger/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/util/testing.py in raise_assert_detail(obj, message, left, right, diff)
   1137         msg = msg + "\n[diff]: {diff}".format(diff=diff)
   1138
-> 1139     raise AssertionError(msg)
   1140
   1141

AssertionError: Series are different

Series values are different (100.0 %)
[left]:  [1]
[right]: [2]

```
@TomAugspurger btw, make sure you can locally conda build (or pip), install into a fresh env and do a
``python -c "import pandas; pandas.test()"`` works (we tests this on travis, but this is a check).

also *after* you tag, but before pushing, make sure the same works for the ``__version__``
thanks @TomAugspurger