Skip to content

Commit 7179145

Browse files
mdesmethashhar
authored andcommitted
Use local Trino if available
1 parent aedef28 commit 7179145

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.github/DEVELOPMENT.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ To run integration tests:
4242
pytest tests/integration
4343
```
4444

45-
They pull a Docker image and then run a container with a Trino server:
45+
If you are already running a local Trino instance on the default port 8080, e.g.
46+
through`docker run -d -p 8080:8080 --name trino --rm trinodb/trino:latest`,
47+
the tests will automatically pick up this server instead of starting a new one
48+
on a random port. This is especially helpful for debugging purposes as you can
49+
inspect the executed queries through [the Trino web ui](http://localhost:8080/),
50+
it also saves you some time as the docker container won't have to be started.
51+
52+
By default, the tests pull a Docker image and then run a container with a Trino
53+
server:
4654
- the image is named `trinodb/trino:${TRINO_VERSION}`
4755
- the container is named `trino-python-client-tests-{uuid4()[:7]}`
4856

tests/integration/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
TRINO_PORT = 8080
3232

3333

34+
def is_trino_available():
35+
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
36+
sock.settimeout(2)
37+
result = sock.connect_ex((TRINO_HOST, DEFAULT_PORT))
38+
if result == 0:
39+
return True
40+
41+
3442
def get_local_port():
3543
with closing(socket.socket()) as s:
3644
s.bind(("localhost", 0))
@@ -134,6 +142,10 @@ def stop_trino(container_id, proc):
134142

135143
@pytest.fixture(scope="module")
136144
def run_trino():
145+
if is_trino_available():
146+
yield None, TRINO_HOST, DEFAULT_PORT
147+
return
148+
137149
image_tag = os.environ.get("TRINO_IMAGE")
138150
if not image_tag:
139151
image_tag = get_default_trino_image_tag()

0 commit comments

Comments
 (0)