|
40 | 40 | Generator, |
41 | 41 | List, |
42 | 42 | Optional, |
43 | | - Union, |
44 | 43 | ) |
45 | 44 | from urllib.parse import urlparse |
46 | 45 |
|
47 | 46 | import boto3 |
48 | 47 | import pyarrow as pa |
49 | 48 | import pytest |
50 | 49 | from moto import mock_dynamodb, mock_glue |
51 | | -from moto.server import ThreadedMotoServer # type: ignore |
52 | 50 |
|
53 | 51 | from pyiceberg import schema |
54 | 52 | from pyiceberg.catalog import Catalog |
|
87 | 85 | from pyiceberg.utils.datetime import datetime_to_millis |
88 | 86 |
|
89 | 87 | if TYPE_CHECKING: |
90 | | - from pytest import ExitCode, Session |
| 88 | + from moto.server import ThreadedMotoServer # type: ignore |
91 | 89 |
|
92 | 90 | from pyiceberg.io.pyarrow import PyArrowFile, PyArrowFileIO |
93 | 91 |
|
@@ -1761,32 +1759,23 @@ def fixture_aws_credentials() -> Generator[None, None, None]: |
1761 | 1759 | os.environ.pop("AWS_DEFAULT_REGION") |
1762 | 1760 |
|
1763 | 1761 |
|
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 | | - |
1775 | 1762 | @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 |
1781 | 1765 |
|
| 1766 | + server = ThreadedMotoServer(ip_address="localhost", port=5001) |
1782 | 1767 |
|
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 |
1784 | 1769 | 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() |
1786 | 1775 |
|
1787 | 1776 |
|
1788 | 1777 | @pytest.fixture(scope="session") |
1789 | | -def moto_endpoint_url(moto_server: ThreadedMotoServer) -> str: |
| 1778 | +def moto_endpoint_url(moto_server: "ThreadedMotoServer") -> str: |
1790 | 1779 | _url = f"http://{moto_server._ip_address}:{moto_server._port}" |
1791 | 1780 | return _url |
1792 | 1781 |
|
|
0 commit comments