Set testing.PORT on all app.create_server() in tests (#1593)

This commit is contained in:
Adam Hopkins 2019-05-30 17:10:00 +03:00 committed by Stephen Sadowski
parent a57c14c70b
commit c15158224b
2 changed files with 17 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import asyncio
import logging import logging
from sanic.config import BASE_LOGO from sanic.config import BASE_LOGO
from sanic.testing import PORT
try: try:
@ -13,7 +14,9 @@ except BaseException:
def test_logo_base(app, caplog): def test_logo_base(app, caplog):
server = app.create_server(debug=True, return_asyncio_server=True) server = app.create_server(
debug=True, return_asyncio_server=True, port=PORT
)
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
loop._stopping = False loop._stopping = False
@ -32,7 +35,9 @@ def test_logo_base(app, caplog):
def test_logo_false(app, caplog): def test_logo_false(app, caplog):
app.config.LOGO = False app.config.LOGO = False
server = app.create_server(debug=True, return_asyncio_server=True) server = app.create_server(
debug=True, return_asyncio_server=True, port=PORT
)
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
loop._stopping = False loop._stopping = False
@ -45,13 +50,17 @@ def test_logo_false(app, caplog):
app.stop() app.stop()
assert caplog.record_tuples[ROW][1] == logging.INFO assert caplog.record_tuples[ROW][1] == logging.INFO
assert caplog.record_tuples[ROW][2] == "Goin' Fast @ http://127.0.0.1:8000" assert caplog.record_tuples[ROW][
2
] == "Goin' Fast @ http://127.0.0.1:{}".format(PORT)
def test_logo_true(app, caplog): def test_logo_true(app, caplog):
app.config.LOGO = True app.config.LOGO = True
server = app.create_server(debug=True, return_asyncio_server=True) server = app.create_server(
debug=True, return_asyncio_server=True, port=PORT
)
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
loop._stopping = False loop._stopping = False
@ -70,7 +79,9 @@ def test_logo_true(app, caplog):
def test_logo_custom(app, caplog): def test_logo_custom(app, caplog):
app.config.LOGO = "My Custom Logo" app.config.LOGO = "My Custom Logo"
server = app.create_server(debug=True, return_asyncio_server=True) server = app.create_server(
debug=True, return_asyncio_server=True, port=PORT
)
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
loop._stopping = False loop._stopping = False

View File

@ -84,7 +84,7 @@ async def test_trigger_before_events_create_server(app):
async def init_db(app, loop): async def init_db(app, loop):
app.db = MySanicDb() app.db = MySanicDb()
await app.create_server(debug=True, return_asyncio_server=True) await app.create_server(debug=True, return_asyncio_server=True, port=PORT)
assert hasattr(app, "db") assert hasattr(app, "db")
assert isinstance(app.db, MySanicDb) assert isinstance(app.db, MySanicDb)