Skip to content

Future <Future pending> attached to a different loop error if hypothesis and @pytest.mark.asyncio are used #117

Closed
@VladimirWork

Description

@VladimirWork

Hello, could you please help me with this issue? I'm trying to send values from hypothesis in async test with await calls inside and getting subject error (I've tried trick from #38 for event_loop but it still doesn't work, also it looks like your hypothesis tests have no awaits inside but asserts only so could you point me to any real example of hypothesis+pytest-asyncio usage?):

platform linux -- Python 3.5.2, pytest-4.3.1, py-1.8.0, pluggy-0.7.1
plugins: hypothesis-4.14.0, testinfra-2.0.0, asyncio-0.10.0

conftest.py:

@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop()
loop.run_until_complete(pool.set_protocol_version(2))
yield loop
loop.close()

test.py:

@settings(verbosity=Verbosity.debug)
@given(test_string=st.characters(whitelist_categories=('N', 'L')))
@pytest.mark.asyncio
async def test_misc_hypothesis(event_loop, test_string):
pool_handle, _ = await pool_helper()
wallet_handle, _, _ = await wallet_helper()
trustee_did, _ = await default_trustee(wallet_handle)
res = await schema_helper(pool_handle, wallet_handle, trustee_did, test_string, '1.0',
json.dumps(["age", "sex", "height", "name"]))
print(res)

stacktrace:

=================================== FAILURES ===================================
_____________________________ test_misc_hypothesis _____________________________

event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>

@settings(verbosity=Verbosity.debug)

@given(test_string=st.characters(whitelist_categories=('N', 'L')))
@pytest.mark.asyncio
async def test_misc_hypothesis(event_loop, test_string):

test_misc.py:623:


/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/_settings.py:402: in local_settings
yield s
/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/utils/dynamicvariables.py:42: in with_value
yield
/usr/local/lib/python3.5/dist-packages/hypothesis/_settings.py:402: in local_settings
yield s
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:568: in execute
result = self.test_runner(data, run)
/usr/local/lib/python3.5/dist-packages/hypothesis/executors.py:56: in default_new_style_executor
return function(data)
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:566: in run
return test(*args, **kwargs)
/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/_settings.py:402: in local_settings
yield s
/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/utils/dynamicvariables.py:42: in with_value
yield
/usr/local/lib/python3.5/dist-packages/hypothesis/_settings.py:402: in local_settings
yield s
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:566: in run
return test(*args, **kwargs)
/usr/local/lib/python3.5/dist-packages/hypothesis/control.py:73: in exit
self.assign_variable.exit(exc_type, exc_value, tb)
/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/utils/dynamicvariables.py:42: in with_value
yield
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:566: in run
return test(*args, **kwargs)
/usr/lib/python3.5/contextlib.py:77: in exit
self.gen.throw(type, value, traceback)
/usr/local/lib/python3.5/dist-packages/hypothesis/internal/entropy.py:104: in deterministic_PRNG
yield
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:566: in run
return test(*args, **kwargs)
/usr/local/lib/python3.5/dist-packages/pytest_asyncio/plugin.py:166: in test_misc_hypothesis
def inner(**kwargs):
/usr/local/lib/python3.5/dist-packages/hypothesis/core.py:529: in test
result = self.test(*args, **kwargs)
/usr/local/lib/python3.5/dist-packages/pytest_asyncio/plugin.py:172: in inner
loop.run_until_complete(future)
/usr/lib/python3.5/asyncio/base_events.py:387: in run_until_complete
return future.result()
/usr/lib/python3.5/asyncio/futures.py:274: in result
raise self._exception
/usr/lib/python3.5/asyncio/tasks.py:241: in _step
result = coro.throw(exc)
test_misc.py:626: in test_misc_hypothesis
pool_handle, _ = await pool_helper()
utils.py:42: in pool_helper
await pool.create_pool_ledger_config(pool_name, pool_config)
/usr/local/lib/python3.5/dist-packages/indy/pool.py:39: in create_pool_ledger_config
create_pool_ledger_config.cb)


self =

def __iter__(self):
    if not self.done():
        self._blocking = True
      yield self  # This tells Task to wait for completion.

E RuntimeError: Task <Task pending coro=<test_misc_hypothesis() running at /home/indy/indy-test-automation/system/test_misc.py:626> cb=[_run_until_complete_cb() at /usr/lib/python3.5/asyncio/base_events.py:164]> got Future attached to a different loop

/usr/lib/python3.5/asyncio/futures.py:361: RuntimeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions