Skip to content

Commit a750b4b

Browse files
authored
Remove MotoServer from the conftest.py scope (#331)
Otherwise we need to have this installed for the tests of the Avro Decoder
1 parent 7f7bb03 commit a750b4b

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

tests/conftest.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@
4040
Generator,
4141
List,
4242
Optional,
43-
Union,
4443
)
4544
from urllib.parse import urlparse
4645

4746
import boto3
4847
import pyarrow as pa
4948
import pytest
5049
from moto import mock_dynamodb, mock_glue
51-
from moto.server import ThreadedMotoServer # type: ignore
5250

5351
from pyiceberg import schema
5452
from pyiceberg.catalog import Catalog
@@ -87,7 +85,7 @@
8785
from pyiceberg.utils.datetime import datetime_to_millis
8886

8987
if TYPE_CHECKING:
90-
from pytest import ExitCode, Session
88+
from moto.server import ThreadedMotoServer # type: ignore
9189

9290
from pyiceberg.io.pyarrow import PyArrowFile, PyArrowFileIO
9391

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

17631761

1764-
MOTO_SERVER = ThreadedMotoServer(ip_address="localhost", port=5001)
1765-
1766-
1767-
def pytest_sessionfinish(
1768-
session: "Session",
1769-
exitstatus: Union[int, "ExitCode"],
1770-
) -> None:
1771-
if MOTO_SERVER._server_ready:
1772-
MOTO_SERVER.stop()
1773-
1774-
17751762
@pytest.fixture(scope="session")
1776-
def moto_server() -> ThreadedMotoServer:
1777-
# this will throw an exception if the port is already in use
1778-
is_port_in_use(MOTO_SERVER._ip_address, MOTO_SERVER._port)
1779-
MOTO_SERVER.start()
1780-
return MOTO_SERVER
1763+
def moto_server() -> "ThreadedMotoServer":
1764+
from moto.server import ThreadedMotoServer
17811765

1766+
server = ThreadedMotoServer(ip_address="localhost", port=5001)
17821767

1783-
def is_port_in_use(ip_address: str, port: int) -> None:
1768+
# this will throw an exception if the port is already in use
17841769
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
1785-
s.bind((ip_address, port))
1770+
s.bind((server._ip_address, server._port))
1771+
1772+
server.start()
1773+
yield server
1774+
server.stop()
17861775

17871776

17881777
@pytest.fixture(scope="session")
1789-
def moto_endpoint_url(moto_server: ThreadedMotoServer) -> str:
1778+
def moto_endpoint_url(moto_server: "ThreadedMotoServer") -> str:
17901779
_url = f"http://{moto_server._ip_address}:{moto_server._port}"
17911780
return _url
17921781

0 commit comments

Comments
 (0)