From f9bd2d8f46875c8087525d00f17c7816c6cc6e90 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 8 Oct 2024 14:13:10 +0200 Subject: [PATCH] Uses subprocess lib to call shell command This will prevent error in case the db name is not compatible with the shell separators --- pytest_odoo.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pytest_odoo.py b/pytest_odoo.py index 526710e..2d4aed5 100644 --- a/pytest_odoo.py +++ b/pytest_odoo.py @@ -7,6 +7,7 @@ import ast import os import signal +import subprocess import threading from contextlib import contextmanager from unittest import mock @@ -138,8 +139,8 @@ 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): @@ -147,7 +148,7 @@ def _worker_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}$"