Skip to content

Commit da6e5f5

Browse files
committed
fix: add pytest-timeout dependency and update related configurations
1 parent 57ccf12 commit da6e5f5

File tree

5 files changed

+33
-78
lines changed

5 files changed

+33
-78
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ test = [
122122
"pytest-mock>=3.14.0",
123123
"pytest-sugar>=1.0.0",
124124
"pytest-xdist>=3.6.1",
125+
"pytest-timeout>=2.3.1",
125126
]
126127

127128
[project.scripts]
@@ -280,6 +281,8 @@ exclude_lines = [
280281
addopts = ["-q", "-ra"]
281282
asyncio_default_fixture_loop_scope = "function"
282283
asyncio_mode = "auto"
284+
timeout = 300
285+
timeout_method = "thread"
283286
filterwarnings = [
284287
"ignore::DeprecationWarning:pkg_resources.*",
285288
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",

sqlspec/adapters/psycopg/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ def _close_pool(self) -> None:
207207
logger.info("Closing Psycopg connection pool", extra={"adapter": "psycopg"})
208208

209209
try:
210-
self.pool_instance._closed = True # pyright: ignore[reportPrivateUsage]
211-
212210
self.pool_instance.close()
213211
logger.info("Psycopg connection pool closed successfully", extra={"adapter": "psycopg"})
214212
except Exception as e:
@@ -402,8 +400,6 @@ async def _close_pool(self) -> None:
402400
return
403401

404402
try:
405-
self.pool_instance._closed = True # pyright: ignore[reportPrivateUsage]
406-
407403
await self.pool_instance.close()
408404
finally:
409405
self.pool_instance = None

tests/integration/test_adapters/test_psycopg/conftest.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sqlspec.adapters.psycopg import PsycopgAsyncConfig, PsycopgSyncConfig
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Generator
11+
from collections.abc import AsyncGenerator, Generator
1212

1313

1414
@pytest.fixture
@@ -25,26 +25,16 @@ def psycopg_sync_config(postgres_service: PostgresService) -> "Generator[Psycopg
2525
config.close_pool()
2626

2727

28-
@pytest.fixture
29-
def psycopg_async_config(postgres_service: PostgresService) -> "Generator[PsycopgAsyncConfig, None, None]":
28+
@pytest.fixture(scope="function")
29+
async def psycopg_async_config(postgres_service: PostgresService) -> "AsyncGenerator[PsycopgAsyncConfig, None]":
3030
"""Create a psycopg async configuration."""
3131
config = PsycopgAsyncConfig(
3232
pool_config={
3333
"conninfo": f"postgresql://{postgres_service.user}:{postgres_service.password}@{postgres_service.host}:{postgres_service.port}/{postgres_service.database}"
3434
}
3535
)
36-
yield config
37-
38-
if config.pool_instance:
39-
import asyncio
40-
41-
try:
42-
loop = asyncio.get_running_loop()
43-
if not loop.is_closed():
44-
loop.run_until_complete(config.close_pool())
45-
except RuntimeError:
46-
new_loop = asyncio.new_event_loop()
47-
try:
48-
new_loop.run_until_complete(config.close_pool())
49-
finally:
50-
new_loop.close()
36+
try:
37+
yield config
38+
finally:
39+
if config.pool_instance:
40+
await config.close_pool()

tests/integration/test_adapters/test_psycopg/test_migrations.py

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,7 @@ def down():
163163
assert len(result.data) == 0
164164
finally:
165165
if config.pool_instance:
166-
import asyncio
167-
168-
try:
169-
asyncio.get_running_loop()
170-
import concurrent.futures
171-
172-
with concurrent.futures.ThreadPoolExecutor() as executor:
173-
future = executor.submit(asyncio.run, config.close_pool())
174-
future.result()
175-
except RuntimeError:
176-
asyncio.run(config.close_pool())
166+
await config.close_pool()
177167

178168

179169
def test_psycopg_sync_multiple_migrations_workflow(postgres_service: PostgresService) -> None:
@@ -380,17 +370,7 @@ def down():
380370
assert len(users_result.data) == 0
381371
finally:
382372
if config.pool_instance:
383-
import asyncio
384-
385-
try:
386-
asyncio.get_running_loop()
387-
import concurrent.futures
388-
389-
with concurrent.futures.ThreadPoolExecutor() as executor:
390-
future = executor.submit(asyncio.run, config.close_pool())
391-
future.result()
392-
except RuntimeError:
393-
asyncio.run(config.close_pool())
373+
await config.close_pool()
394374

395375

396376
def test_psycopg_sync_migration_current_command(postgres_service: PostgresService) -> None:
@@ -509,17 +489,7 @@ def down():
509489
assert current_version is None or current_version == "base"
510490
finally:
511491
if config.pool_instance:
512-
import asyncio
513-
514-
try:
515-
asyncio.get_running_loop()
516-
import concurrent.futures
517-
518-
with concurrent.futures.ThreadPoolExecutor() as executor:
519-
future = executor.submit(asyncio.run, config.close_pool())
520-
future.result()
521-
except RuntimeError:
522-
asyncio.run(config.close_pool())
492+
await config.close_pool()
523493

524494

525495
def test_psycopg_sync_migration_error_handling(postgres_service: PostgresService) -> None:
@@ -618,17 +588,7 @@ def down():
618588
assert "no such" in str(e).lower() or "does not exist" in str(e).lower()
619589
finally:
620590
if config.pool_instance:
621-
import asyncio
622-
623-
try:
624-
asyncio.get_running_loop()
625-
import concurrent.futures
626-
627-
with concurrent.futures.ThreadPoolExecutor() as executor:
628-
future = executor.submit(asyncio.run, config.close_pool())
629-
future.result()
630-
except RuntimeError:
631-
asyncio.run(config.close_pool())
591+
await config.close_pool()
632592

633593

634594
def test_psycopg_sync_migration_with_transactions(postgres_service: PostgresService) -> None:
@@ -793,14 +753,4 @@ def down():
793753
assert len(result.data) == 0
794754
finally:
795755
if config.pool_instance:
796-
import asyncio
797-
798-
try:
799-
asyncio.get_running_loop()
800-
import concurrent.futures
801-
802-
with concurrent.futures.ThreadPoolExecutor() as executor:
803-
future = executor.submit(asyncio.run, config.close_pool())
804-
future.result()
805-
except RuntimeError:
806-
asyncio.run(config.close_pool())
756+
await config.close_pool()

uv.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)