Skip to content

Commit

Permalink
Uses subprocess lib to call shell command
Browse files Browse the repository at this point in the history
This will prevent error in case the db name is not compatible with the shell separators
  • Loading branch information
lmignon committed Oct 8, 2024
1 parent 1c9d17a commit f9bd2d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pytest_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ast
import os
import signal
import subprocess
import threading
from contextlib import contextmanager
from unittest import mock
Expand Down Expand Up @@ -138,16 +139,16 @@ def _worker_db_name():
try:
if xdist_worker:
db_name = f"{original_db_name}-{xdist_worker}"
os.system(f"dropdb {db_name} --if-exists")
os.system(f"createdb -T {original_db_name} {db_name}")
subprocess.run(["dropdb", db_name, "--if-exists"], check=True)
subprocess.run(["createdb", "-T", original_db_name, db_name], check=True)
odoo.tools.config["db_name"] = db_name
odoo.tools.config["dbfilter"] = f"^{db_name}$"
with _shared_filestore(original_db_name, db_name):
yield db_name
finally:
if db_name != original_db_name:
odoo.sql_db.close_db(db_name)
os.system(f"dropdb {db_name}")
subprocess.run(["dropdb", db_name, "--if-exists"], check=True)
odoo.tools.config["db_name"] = original_db_name
odoo.tools.config["dbfilter"] = f"^{original_db_name}$"

Expand Down

0 comments on commit f9bd2d8

Please sign in to comment.