Python pytest导致异步IO循环失败

Python pytest导致异步IO循环失败,python,python-3.x,pytest,Python,Python 3.x,Pytest,因此,在任何包含循环的文件上运行pytest都会产生错误 test_post.py:6: in <module> loop = asyncio.get_event_loop() /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py:678: in get_event_loop return get_event_loop_p

因此,在任何包含循环的文件上运行pytest都会产生错误

test_post.py:6: in <module>
loop = asyncio.get_event_loop()
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py:678: in get_event_loop
    return get_event_loop_policy().get_event_loop()
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py:584: in get_event_loop
    % threading.current_thread().name)
E   RuntimeError: There is no current event loop in thread 'MainThread'.

这些不是我想要编写的实际测试,但我需要先让循环工作。。。有没有关于如何修复的想法?

添加一个
\uuuu main\uuuuu
入口点,并将
loop=asyncio.get\u event\u loop()
放在该入口点下方

import pytest
#from handlers import request_handler
import json

import asyncio
loop = asyncio.get_event_loop()
async def compute(x, y):
  print("Compute %s + %s ..." % (x, y))
  await asyncio.sleep(1.0)
  return x + y

async def print_sum(x, y):
  result = await compute(x, y)
  print("%s + %s = %s" % (x, y, result))
loop.run_until_complete( print_sum(1, 2) )
loop.close()