Let SanicTestClient has its own port

For parallel test running, the servers must have different ports.
See examples/pytest_xdist.py for example.
This commit is contained in:
Jeong YunWon
2017-11-06 17:26:11 +09:00
parent 098cd70e82
commit ed8725bf6c
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: