Skip to content

Commit

Permalink
Remove MotoServer from the conftest.py scope (#331)
Browse files Browse the repository at this point in the history
Otherwise we need to have this installed for the
tests of the Avro Decoder
  • Loading branch information
Fokko authored Jan 30, 2024
1 parent 7f7bb03 commit a750b4b
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@
Generator,
List,
Optional,
Union,
)
from urllib.parse import urlparse

import boto3
import pyarrow as pa
import pytest
from moto import mock_dynamodb, mock_glue
from moto.server import ThreadedMotoServer # type: ignore

from pyiceberg import schema
from pyiceberg.catalog import Catalog
Expand Down Expand Up @@ -87,7 +85,7 @@
from pyiceberg.utils.datetime import datetime_to_millis

if TYPE_CHECKING:
from pytest import ExitCode, Session
from moto.server import ThreadedMotoServer # type: ignore

from pyiceberg.io.pyarrow import PyArrowFile, PyArrowFileIO

Expand Down Expand Up @@ -1761,32 +1759,23 @@ def fixture_aws_credentials() -> Generator[None, None, None]:
os.environ.pop("AWS_DEFAULT_REGION")


MOTO_SERVER = ThreadedMotoServer(ip_address="localhost", port=5001)


def pytest_sessionfinish(
session: "Session",
exitstatus: Union[int, "ExitCode"],
) -> None:
if MOTO_SERVER._server_ready:
MOTO_SERVER.stop()


@pytest.fixture(scope="session")
def moto_server() -> ThreadedMotoServer:
# this will throw an exception if the port is already in use
is_port_in_use(MOTO_SERVER._ip_address, MOTO_SERVER._port)
MOTO_SERVER.start()
return MOTO_SERVER
def moto_server() -> "ThreadedMotoServer":
from moto.server import ThreadedMotoServer

server = ThreadedMotoServer(ip_address="localhost", port=5001)

def is_port_in_use(ip_address: str, port: int) -> None:
# this will throw an exception if the port is already in use
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((ip_address, port))
s.bind((server._ip_address, server._port))

server.start()
yield server
server.stop()


@pytest.fixture(scope="session")
def moto_endpoint_url(moto_server: ThreadedMotoServer) -> str:
def moto_endpoint_url(moto_server: "ThreadedMotoServer") -> str:
_url = f"http://{moto_server._ip_address}:{moto_server._port}"
return _url

Expand Down

0 comments on commit a750b4b

Please sign in to comment.