fix(tests): repair test_profile_duplicate_names so the suite can run

The file still used the pre-refactor flat imports and a sys.path hack:

    sys.path.insert(0, str(Path(__file__).parent.parent))
    from database import Base, VoiceProfile as DBVoiceProfile
    from profiles import create_profile, update_profile

`profiles` now lives at backend/services/profiles.py, so collection raised
ImportError. Because pytest aborts the whole run on a collection error, this
one file meant `just test` ran zero tests — duplicate-name validation has had
no coverage since the services refactor.

Switch to package imports like every other test module, and drop
DBVoiceProfile, which was imported but never used.

That exposed a second, latent bug: all 6 tests passed but every one errored in
teardown with PermissionError WinError 32. The fixture closed the session and
then rmtree'd the temp dir, but closing a session does not release
SQLAlchemy's pooled connection, so SQLite still held test.db open on Windows.
Dispose the engine before removing the directory.

6 passed, and full-suite collection goes from aborting to 170 tests.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Lvigentini
2026-10-04 00:01:11 +00:00
committed by capy-ai-staging[bot]
co-authored by Claude Opus 5
parent 3e240a9ef1
commit 63f09455ef
@@ -12,7 +12,7 @@ from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from backend.database import Base, VoiceProfile as DBVoiceProfile
from backend.database import Base
from backend.models import VoiceProfileCreate
from backend.services.profiles import create_profile, update_profile
@@ -33,8 +33,11 @@ def test_db():
yield db
# Cleanup
# Cleanup. The engine must be disposed as well as the session closed —
# on Windows the pooled connection keeps the .db file open and rmtree
# fails with WinError 32.
db.close()
engine.dispose()
shutil.rmtree(temp_dir)