Closed jborman-exos closed 1 year ago
Thanks for the thorough report! I think only OSError: [Errno 99] Cannot assign requested address
is relevant; the rest is just a failed connection after that. I'm not sure what's going on here.
Is there a reason you're binding to 0.0.0.0 instead of localhost? We do a similar Uvicorn serve pattern for our login CLI: https://github.com/PrefectHQ/prefect/blob/main/src/prefect/cli/cloud.py#L101-L102
Good point on the addresses in the fixture - I noticed that I was being inconsistent with my use of localhost
and 0.0.0.0
. That lead me to update my fixture:
@pytest_asyncio.fixture(name='orion_api_url')
async def hosted_orion_api(
unused_tcp_port: int,
tmp_path_factory: TempPathFactory,
) -> AsyncGenerator[str, None]: # pragma: no cover
"""
Runs an instance of the Orion API at a dedicated URL instead of the
ephemeral application.
Uses the same database as the rest of the tests.
Yields:
The connection string
"""
# Disabe Orion telemetry for tests
prefect_home = str(tmp_path_factory.mktemp('prefect').absolute())
os.environ['PREFECT_HOME'] = prefect_home
os.environ['PREFECT_ORION_ANALYTICS_ENABLED'] = 'false'
host = '0.0.0.0' # <- Works
# host = 'localhost' # <- Does not work
config = uvicorn.Config(
app=create_app(ephemeral=True),
host=host,
port=unused_tcp_port,
)
server = uvicorn.Server(config)
task = asyncio.create_task(server.serve())
yield f'http://{host}:{unused_tcp_port}/api'
await server.shutdown()
task.cancel()
I'm seeing that using 'localhost'
causes the error above, but '0.0.0.0'
passes. This could be related to my environment (Ubuntu Docker container)?
Have you tried "127.0.0.1"? I'm not sure "localhost"
is supported.
This could be related to my environment (Ubuntu Docker container)?
I'm not sure, it seems like it should behave fine in a container.
Have you tried "127.0.0.1"? I'm not sure "localhost" is supported.
Yep, that was it 😄 Thanks for the help @madkinsz
First check
Bug summary
I am trying to standup the Orion
FastAPI
app as apytest
fixture to use for internal integration testing. My fixture is based off of thehosted_orion_api
fixture fromprefect.testing.fixtures
but runs the app as a task in the event loop.Reproduction
Error
Versions
Additional context
Pytest session info:
OS Info: