Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import shutil
import sys
import tempfile
import threading

import pytest
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions tests/test_async_executor.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -15,15 +13,15 @@
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
assertion shape that let ArcadeData/arcadedb#7615 through: at level 4 the
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))
Expand Down
6 changes: 2 additions & 4 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import csv
import os
import tempfile
from pathlib import Path

import pytest
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_free_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_import_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/test_resultset_read_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import os
import shutil
import tempfile

import jpype
import pytest
Expand Down Expand Up @@ -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():
Expand Down
6 changes: 2 additions & 4 deletions tests/test_server_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading