conftest.py 774 B

1234567891011121314151617181920212223242526272829303132
  1. # coding: utf-8
  2. import pytest
  3. from echo import api
  4. @pytest.yield_fixture(autouse=True)
  5. def redis():
  6. """ Redis
  7. We uses a normal(not asyncio) version of redis lib here because of some
  8. issues using asyncio version and yield fixtures.
  9. """
  10. import redis
  11. redis = redis.StrictRedis(host='127.0.0.1', port=6379)
  12. yield redis
  13. redis.flushdb()
  14. @pytest.yield_fixture()
  15. def api_server(event_loop, unused_tcp_port):
  16. tcp_port = unused_tcp_port
  17. server, handler, redis_pool = event_loop.run_until_complete(
  18. api.start(event_loop, tcp_port))
  19. yield 'http://127.0.0.1:{}/'.format(tcp_port)
  20. event_loop.run_until_complete(handler.finish_connections(1.0))
  21. event_loop.run_until_complete(redis_pool.clear())
  22. api.stop(event_loop)