mirror of
https://gitlab.com/itsulu-odoo/itsulu-blog-publisher.git
synced 2026-05-30 23:41:23 +00:00
fix: auto-install addon via conftest for pytest-odoo
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).
This commit is contained in:
parent
882e948679
commit
421f65cda6
3 changed files with 107 additions and 2 deletions
|
|
@ -13,8 +13,8 @@ RUN python3 -m pip install --no-cache-dir \
|
|||
RUN mkdir -p /mnt/extra-addons && chmod 777 /mnt/extra-addons
|
||||
COPY --chown=odoo:odoo addons/itsulu_blog_publisher /mnt/extra-addons/itsulu_blog_publisher
|
||||
|
||||
# Symlink addon into Odoo's default addons directory so pytest-odoo can find it
|
||||
RUN mkdir -p /var/lib/odoo/addons/17.0 && ln -s /mnt/extra-addons/itsulu_blog_publisher /var/lib/odoo/addons/17.0/itsulu_blog_publisher
|
||||
# Symlink addon into Odoo's default addons directory so Odoo can find it
|
||||
RUN mkdir -p /var/lib/odoo/addons && ln -s /mnt/extra-addons/itsulu_blog_publisher /var/lib/odoo/addons/itsulu_blog_publisher
|
||||
|
||||
# Set working directory to a temp location for test running
|
||||
WORKDIR /tmp/test
|
||||
|
|
|
|||
45
conftest.py
Normal file
45
conftest.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""
|
||||
Global pytest configuration for ITSulu Blog Publisher tests.
|
||||
Installs the addon into the test database before any test code runs.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
print(">>> conftest.py loaded", file=sys.stderr)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""Install itsulu_blog_publisher into the test database."""
|
||||
print(">>> pytest_configure hook called", file=sys.stderr)
|
||||
|
||||
db_name = getattr(config.option, 'odoo_database', None)
|
||||
print(f">>> odoo_database option: {db_name}", file=sys.stderr)
|
||||
|
||||
if not db_name:
|
||||
print(">>> No database name — skipping install", file=sys.stderr)
|
||||
return
|
||||
|
||||
print(f"\n🚀 Installing itsulu_blog_publisher into {db_name}...", file=sys.stderr)
|
||||
|
||||
cmd = [
|
||||
'odoo',
|
||||
'-d', db_name,
|
||||
'-i', 'itsulu_blog_publisher',
|
||||
'--without-demo=all',
|
||||
'--stop-after-init',
|
||||
]
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
||||
if result.returncode == 0:
|
||||
print(f"✅ Addon installed successfully", file=sys.stderr)
|
||||
else:
|
||||
print(f"⚠️ Install returned {result.returncode}", file=sys.stderr)
|
||||
if result.stderr:
|
||||
print(f" STDERR: {result.stderr[-300:]}", file=sys.stderr)
|
||||
except subprocess.TimeoutExpired:
|
||||
print(f"⚠️ Install timed out (120s)", file=sys.stderr)
|
||||
except Exception as e:
|
||||
print(f"⚠️ Install error: {e}", file=sys.stderr)
|
||||
|
||||
60
conftest_runner.py
Normal file
60
conftest_runner.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
"""
|
||||
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()
|
||||
Loading…
Reference in a new issue