Correcting Warnings from IPython tab completion tests with async tests
State: closed

- [ ] closes #29070 
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

I tried to follow what Tom said in the issue but I don't really know how to integrate with CI. I was in doubt too with how to import pytest-asyncio as well. Maybe both questions are related.

If is possible for someone to explain, I will quickly make the necessary changes 😁


Labels:
name: Testing
description: pandas testing functions or related to the test suite
name: Output-Formatting
description: __repr__ of pandas objects, to_string

Comments:
We need to add pytest-asyncio to the CI files in `ci/deps/`. Anywhere you see IPython.

Though I wonder, for something this small, I wonder if it's possible to just write our own little helper to run the test?
note averse to adding pytest-asyncio, and +1 rather than rolling our own here.
So should I add to `ci/deps/` ? If not could you explain a little more about this little helper you suggested that we write?
@gabriellm1 yea add it to the config files in the ci folder that currently have ipython. Will also want to add to `environment.yaml` and then run `scripts/generate_pip_deps_from_conda.py` before commit
I'm not sure what the best way to avoid the failure

```
==================================== ERRORS ====================================
______ ERROR collecting pandas/tests/arrays/categorical/test_warnings.py _______
'asyncio' not found in `markers` configuration option
--------- generated xml file: /home/vsts/work/1/s/test-data-single.xml ---------
========================== slowest 10 test durations ===========================
```

I think that's from not having pytest-asyncio in that CI env.

Ideally, we would work without that marker though, since this is an optional test dependency.
Hm, I see. So what should be my next move from here?
I'm not sure. I would see if there's a way to dynamically register pytest
markers in `pandas/conftest.py`. Something like

```python
try:
    import pytest_asyncio
except ImportError:
    asyncio = pytest.mark.skip(reason="pytest-asyncio not installed.")
    # does that need to be registered with pytest somehow?
```

On Tue, Oct 22, 2019 at 6:59 PM Gabriel Monteiro <notifications@github.com>
wrote:

> Hm, I see. So what should be my next move from here?
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/29087?email_source=notifications&email_token=AAKAOIWBSEE2SXEC7INXJITQP6HWRA5CNFSM4JCNVCEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEB7SWRI#issuecomment-545205061>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAKAOIUXSWNIQZENVACHLRLQP6HWRANCNFSM4JCNVCEA>
> .
>

I really don't know where to go from here guys. Should I close it or wait for some help?
@gabriellm1 - this is almost there steps to completion:
1) Merge master - we have recently dropped python 3.5 support + builds
2) Instead of using @pytest.mark.asyncio
You can do:
```
# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
```
Which will automatically mark all coroutine test functions.

(Think this might help some of the problems mentioned above)

3) Run isort that's causing the code checks CI to fail.
I think the issue was with making pytest-asyncio optional. Will investigate
quick.

On Sun, Nov 17, 2019 at 10:13 AM alimcmaster1 <notifications@github.com>
wrote:

> @gabriellm1 <https://github.com/gabriellm1> - I think this is almost
> there steps to completion I think
>
>    1. Merge master - we have recently dropped python 3.5 support + builds
>    2. Instead of using @pytest.mark.asyncio
>    You can do:
>
> # All test coroutines will be treated as marked.
> pytestmark = pytest.mark.asyncio
>
> Which will automatically mark all coroutine test functions.
>
> (Think this might help some of the problems mentioned above)
>
>    1. Run isort that's causing the code checks CI to fail.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/29087?email_source=notifications&email_token=AAKAOISWKFQPVCOJL2IPVQLQUFUUDA5CNFSM4JCNVCEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEIPX7A#issuecomment-554761212>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAKAOIRUQ6D26UO6CWISYL3QUFUUDANCNFSM4JCNVCEA>
> .
>

Well, it's not pretty but this does the trick

```python
import warnings
import pytest


ignore_coro_warnings = pytest.mark.filterwarnings("ignore::pytest.PytestUnhandledCoroutineWarning")

try:
    import pytest_asyncio

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        async_mark = pytest.mark.asyncio
except ImportError:
    async_mark = pytest.mark.skip(reason="Missing pytest-asyncio")


@async_mark
@ignore_coro_warnings
async def test_foo():
    assert 0
```

Can you define those marks and apply them in every place that needs them? Then we don't need a hard test dependency on pytest-asyncio (which probably isn't worth it).
@gabriellm1 can you address conflicts and incorporate feedback from @TomAugspurger ?
@gabriellm1 is this still active? I can potentially take a look if you are no longer wanting to work on this. 

Thanks,

Ali
Closing as stale - reopened here https://github.com/pandas-dev/pandas/pull/30689