diff --git a/tests/conftest.py b/tests/conftest.py index 3e03cdc..c49cf70 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ import os import shutil import sys -import tempfile import threading import pytest @@ -365,18 +364,24 @@ def free_port(): @pytest.fixture -def temp_server_root(): - """Create a temporary server root directory.""" - temp_dir = tempfile.mkdtemp(prefix="arcadedb_test_server_") +def temp_server_root(tmp_path_factory): + """Create a temporary server root directory (under pytest's basetemp).""" + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_server_")) yield temp_dir if os.path.exists(temp_dir): shutil.rmtree(temp_dir) @pytest.fixture -def temp_db_path(): - """Create a temporary database path.""" - temp_dir = tempfile.mkdtemp(prefix="arcadedb_test_db_") +def temp_db_path(tmp_path_factory): + """Create a temporary database path (under pytest's basetemp). + + pytest keeps only its last three basetemp runs, so a killed run (teardown + never runs) leaves nothing permanent in the system temp directory. The + explicit close and rmtree with the Windows retry stay: pytest's own cleanup + is lazy and cannot retry a directory the JVM still holds open. + """ + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_db_")) db_path = os.path.join(temp_dir, "test_db") yield db_path # Cleanup @@ -402,11 +407,11 @@ def temp_db_path(): @pytest.fixture -def temp_db(): +def temp_db(tmp_path_factory): """Create a temporary database, yield it, and clean up.""" import arcadedb - temp_dir = tempfile.mkdtemp(prefix="arcadedb_test_db_") + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_db_")) db_path = os.path.join(temp_dir, "test_db") db = arcadedb.create_database(db_path) @@ -449,13 +454,13 @@ def temp_db(): @pytest.fixture -def temp_dir_factory(): +def temp_dir_factory(tmp_path_factory): """Factory fixture to create multiple temporary directories with cleanup.""" temp_dirs = [] def _create_temp_dir(prefix="arcadedb_test_"): """Create a temporary directory and register it for cleanup.""" - temp_dir = tempfile.mkdtemp(prefix=prefix) + temp_dir = str(tmp_path_factory.mktemp(prefix)) temp_dirs.append(temp_dir) return temp_dir diff --git a/tests/test_async_executor.py b/tests/test_async_executor.py index 41393f4..8b4b5d3 100644 --- a/tests/test_async_executor.py +++ b/tests/test_async_executor.py @@ -1,10 +1,8 @@ """Tests for AsyncExecutor with SQL/Cypher-first usage.""" import shutil -import tempfile import threading import time -from pathlib import Path import pytest @@ -15,7 +13,7 @@ LOSS_REPRO_ROWS = 9_742 -def test_async_executor_sql_command_insert_is_exact_at_parallel_one(): +def test_async_executor_sql_command_insert_is_exact_at_parallel_one(tmp_path): """Every command submitted at parallel level 1 becomes a row. This used to run at parallel level 4 and assert `count > 0`, which is the @@ -23,7 +21,7 @@ def test_async_executor_sql_command_insert_is_exact_at_parallel_one(): executor stored a quarter of what it was given (before 26.10.1, fixed in #7625) and `count > 0` still passed. """ - db_path = Path(tempfile.mkdtemp()) / "test_async_sql_insert" + db_path = tmp_path / "test_async_sql_insert" try: db = arcadedb.create_database(str(db_path)) diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 7e2afd6..59c0739 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -24,15 +24,13 @@ @pytest.fixture -def cleanup_db(): +def cleanup_db(tmp_path_factory): """Fixture to clean up test databases.""" - import tempfile - db_paths = [] def _create_temp_db(prefix="arcadedb_test_"): """Create a temporary database directory and register it for cleanup.""" - temp_dir = tempfile.mkdtemp(prefix=prefix) + temp_dir = str(tmp_path_factory.mktemp(prefix)) db_paths.append(temp_dir) return temp_dir diff --git a/tests/test_exporter.py b/tests/test_exporter.py index d43663d..743e2de 100644 --- a/tests/test_exporter.py +++ b/tests/test_exporter.py @@ -5,7 +5,6 @@ import csv import os -import tempfile from pathlib import Path import pytest @@ -14,9 +13,9 @@ @pytest.fixture -def temp_db_path(): +def temp_db_path(tmp_path_factory): """Create a temporary database path.""" - temp_dir = tempfile.mkdtemp() + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_db_")) db_path = os.path.join(temp_dir, "test_export_db") yield db_path # Cleanup diff --git a/tests/test_free_threading.py b/tests/test_free_threading.py index 7a110f6..ad7a130 100644 --- a/tests/test_free_threading.py +++ b/tests/test_free_threading.py @@ -332,8 +332,8 @@ def first_start_race(tmp, n=THREADS): @pytest.fixture -def tmp(): - d = tempfile.mkdtemp(prefix="arcadedb_ft_") +def tmp(tmp_path_factory): + d = str(tmp_path_factory.mktemp("arcadedb_ft_")) yield d shutil.rmtree(d, ignore_errors=True) diff --git a/tests/test_import_database.py b/tests/test_import_database.py index 3c15cad..9f1803f 100644 --- a/tests/test_import_database.py +++ b/tests/test_import_database.py @@ -10,8 +10,8 @@ @pytest.fixture -def temp_db_path(): - temp_dir = tempfile.mkdtemp() +def temp_db_path(tmp_path_factory): + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_db_")) db_path = os.path.join(temp_dir, "test_import_database_db") yield db_path diff --git a/tests/test_resultset_read_errors.py b/tests/test_resultset_read_errors.py index d3986fb..b812085 100644 --- a/tests/test_resultset_read_errors.py +++ b/tests/test_resultset_read_errors.py @@ -14,7 +14,6 @@ import os import shutil -import tempfile import jpype import pytest @@ -63,8 +62,8 @@ def _to_dataframe(rs): @pytest.fixture(scope="module") -def db(): - temp_dir = tempfile.mkdtemp(prefix="arcadedb_test_db_") +def db(tmp_path_factory): + temp_dir = str(tmp_path_factory.mktemp("arcadedb_test_db_")) database = arcadedb.create_database(os.path.join(temp_dir, "test_db")) database.command("sql", "CREATE DOCUMENT TYPE E BUCKETS 1") with database.transaction(): diff --git a/tests/test_server_patterns.py b/tests/test_server_patterns.py index c77791d..e2161a8 100644 --- a/tests/test_server_patterns.py +++ b/tests/test_server_patterns.py @@ -40,16 +40,14 @@ def _http_query(server, db_name, sql): @pytest.fixture -def cleanup_test_dirs(): +def cleanup_test_dirs(tmp_path_factory): """Fixture to clean up test directories and servers.""" - import tempfile - dirs = [] servers = [] def _create_temp_dir(prefix="arcadedb_test_"): """Create a temporary directory and register it for cleanup.""" - temp_dir = tempfile.mkdtemp(prefix=prefix) + temp_dir = str(tmp_path_factory.mktemp(prefix)) dirs.append(temp_dir) return temp_dir