Creates conftest.py that installs the addon before tests run via the pytest_configure hook. Also fixes Dockerfile symlink path for Odoo 17 (no version subdirectory).
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""
|
|
Conftest for running ITSulu Blog Publisher tests.
|
|
This is placed OUTSIDE the addon package to avoid auto-importing it.
|
|
Copy this to /mnt/extra-addons/conftest.py in the Docker build.
|
|
"""
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
|
|
sys.stderr.write(">>> conftest_runner loaded from /mnt/extra-addons\n")
|
|
sys.stderr.flush()
|
|
|
|
|
|
def pytest_configure(config):
|
|
"""Install itsulu_blog_publisher into the test database."""
|
|
sys.stderr.write(">>> pytest_configure hook called\n")
|
|
sys.stderr.flush()
|
|
|
|
db_name = getattr(config.option, 'odoo_database', None)
|
|
sys.stderr.write(f">>> odoo_database option: {db_name}\n")
|
|
sys.stderr.flush()
|
|
|
|
if not db_name:
|
|
sys.stderr.write(">>> No database name — skipping install\n")
|
|
sys.stderr.flush()
|
|
return
|
|
|
|
sys.stderr.write(f"\n🚀 Installing itsulu_blog_publisher into {db_name}...\n")
|
|
sys.stderr.flush()
|
|
|
|
pg_host = os.environ.get('PGHOST', 'localhost')
|
|
pg_user = os.environ.get('PGUSER', 'odoo')
|
|
|
|
cmd = [
|
|
'odoo',
|
|
'-d', db_name,
|
|
'-i', 'itsulu_blog_publisher',
|
|
'--without-demo=all',
|
|
'--stop-after-init',
|
|
'--db_host', pg_host,
|
|
'--db_user', pg_user,
|
|
]
|
|
|
|
try:
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
|
sys.stderr.write(f" Install exit code: {result.returncode}\n")
|
|
if result.returncode == 0:
|
|
sys.stderr.write(f"✅ Addon installed successfully\n")
|
|
else:
|
|
sys.stderr.write(f"⚠️ Install returned {result.returncode}\n")
|
|
if result.stderr:
|
|
sys.stderr.write(f" STDERR: {result.stderr[-500:]}\n")
|
|
sys.stderr.flush()
|
|
except subprocess.TimeoutExpired:
|
|
sys.stderr.write(f"⚠️ Install timed out (120s)\n")
|
|
sys.stderr.flush()
|
|
except Exception as e:
|
|
sys.stderr.write(f"⚠️ Install error: {e}\n")
|
|
sys.stderr.flush()
|