Merge pull request #1008 from youknowone/pytest-xdist

Let SanicTestClient has its own port
This commit is contained in:
Raphael Deem
2017-11-10 10:50:01 -08:00
committed by GitHub
2 changed files with 53 additions and 3 deletions

View File

@@ -8,8 +8,9 @@ PORT = 42101
class SanicTestClient:
def __init__(self, app):
def __init__(self, app, port=PORT):
self.app = app
self.port = port
async def _local_request(self, method, uri, cookies=None, *args, **kwargs):
import aiohttp
@@ -17,7 +18,7 @@ class SanicTestClient:
url = uri
else:
url = 'http://{host}:{port}{uri}'.format(
host=HOST, port=PORT, uri=uri)
host=HOST, port=self.port, uri=uri)
logger.info(url)
conn = aiohttp.TCPConnector(verify_ssl=False)
@@ -66,7 +67,7 @@ class SanicTestClient:
exceptions.append(e)
self.app.stop()
self.app.run(host=HOST, debug=debug, port=PORT, **server_kwargs)
self.app.run(host=HOST, debug=debug, port=self.port, **server_kwargs)
self.app.listeners['after_server_start'].pop()
if exceptions: