Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'asyncio' has no attribute 'ensure_future' with pytest-xdist #55

Closed
orf opened this issue Jun 4, 2017 · 6 comments

Comments

@orf
Copy link

orf commented Jun 4, 2017

If you attempt to use pytest-asyncio with pytest-xdist, and run py.test -n 4 it will fail with the exception in the title at this line.

Running it without -n 4 works as expected. I'm not sure what's going on here or why that attribute would be missing.

@orf
Copy link
Author

orf commented Jun 4, 2017

Hmm, that MR seems to pass. On my mac, I get:

⇒  py.test -n 4 .                                                                                                          (env: x)
=========================================================== test session starts ============================================================
platform darwin -- Python 3.6.1, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: /Users/x/PycharmProjects/x, inifile:
plugins: xdist-1.16.0, asyncio-0.6.0
gw0 [2] / gw1 [2] / gw2 [2] / gw3 [2]
scheduling tests via LoadScheduling
.F
================================================================= FAILURES =================================================================
___________________________________________________________ test_basic_pipeline ____________________________________________________________
[gw0] darwin -- Python 3.6.1 /Users/x/.virtualenvs/x/bin/python3.6
pyfuncitem = <Function 'test_basic_pipeline'>

    @pytest.mark.tryfirst
    def pytest_pyfunc_call(pyfuncitem):
        """
        Run asyncio marked test functions in an event loop instead of a normal
        function call.
        """
        for marker_name, fixture_name in _markers_2_fixtures.items():
            if marker_name in pyfuncitem.keywords:
                event_loop = pyfuncitem.funcargs[fixture_name]

                funcargs = pyfuncitem.funcargs
                testargs = {arg: funcargs[arg]
                            for arg in pyfuncitem._fixtureinfo.argnames}
                event_loop.run_until_complete(
>                   asyncio.ensure_future(
                        pyfuncitem.obj(**testargs), loop=event_loop))
E               AttributeError: module 'asyncio' has no attribute 'ensure_future'

../../.virtualenvs/x/lib/python3.6/site-packages/pytest_asyncio/plugin.py:154: AttributeError
==================================================== 1 failed, 1 passed in 0.59 seconds ====================================================
x@mac:~/PycharmProjects/x|master⚡
⇒

But also:

⇒  py.test                                                                                                                 (env: x)
=========================================================== test session starts ============================================================
platform darwin -- Python 3.6.1, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: /Users/x/PycharmProjects/x, inifile:
plugins: xdist-1.16.0, asyncio-0.6.0
collected 2 items

test/test_pipeline.py .
test/test_task.py .

========================================================= 2 passed in 0.03 seconds =========================================================

@Tinche
Copy link
Member

Tinche commented Jun 5, 2017

I can't reproduce this, even on macOs. The error makes me think pytest-xdist is using a different Python to run its tests.

Running under pytest-xdist I get another failure, but this is due to the tests assuming they're running in a single process.

@orf
Copy link
Author

orf commented Jun 5, 2017 via email

@orf
Copy link
Author

orf commented Jun 5, 2017

Ahh, it can't be that though @Tinche - if you look at the error stacktrace it's pointing at the correct Python version (3.6).

@daniel-kg
Copy link

daniel-kg commented Oct 5, 2017

I'm having the exact same problem, but on ubuntu. Details are:

Ubuntu 16.04.3 LTS
pytest-xdist==1.20.0
python 3.6.2

Here's the full ouput of pip freeze in case it's some weird interaction with some of the other packages.

aiohtp==2.2.5
aiomas==1.0.3
aiopg==0.13.0
apipkg==1.4
arrow==0.10.0
async-generator==1.8
async-timeout==1.3.0
asyncio==3.4.3
asyncio-extras==1.3.0
asyncpg==0.12.0
asynctest==0.10.0
blosc==1.5.1
Cerberus==1.1
certifi==2017.7.27.1
chardet==3.0.4
dateutils==0.6.6
decorator==4.0.11
docker==2.5.1
docker-pycreds==0.2.1
execnet==1.4.1
extras==1.0.0
fancycompleter==0.7
flake8==3.3.0
frozendict==1.2
idna==2.5
ipdb==0.10.3
ipython==6.1.0
ipython-genutils==0.2.0
iso8601==0.1.12
jedi==0.10.2
line-profiler==2.0
link==1.2.4
link.crdt==1.0
mccabe==0.6.1
mock==2.0.0
msgpack-python==0.4.8
multidict==3.1.3
numpy==1.13.1
oauthlib==2.0.2
pandas==0.20.3
pbr==3.1.1
pexpect==4.2.1
pickleshare==0.7.4
pkg-resources==0.0.0
prompt-toolkit==1.0.14
psycopg2==2.7.1
ptyprocess==0.5.1
py==1.4.34
pycodestyle==2.3.1
pyflakes==1.5.0
Pygments==2.2.0
pytest==3.1.2
pytest-asyncio==0.6.0
pytest-forked==0.2
pytest-xdist==1.20.0
python-dateutil==2.6.0
pytz==2017.2
requests==2.18.3
requests-oauthlib==0.8.0
simplegeneric==0.8.1
six==1.10.0
traitlets==4.3.2
ujson==1.35
urllib3==1.22
uvloop==0.8.0
wcwidth==0.1.7
websocket-client==0.44.0
wmctrl==0.3
xmltodict==0.11.0
yapf==0.16.2
yarl==0.12.0

@asvetlov
Copy link
Contributor

asvetlov commented Jan 6, 2022

ensure_future() was introduced by Python 3.5.

I suggest closing the issue.

@Tinche Tinche closed this as completed Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants