Skip to content

Commit f9bd2d8

Browse files
committed
Uses subprocess lib to call shell command
This will prevent error in case the db name is not compatible with the shell separators
1 parent 1c9d17a commit f9bd2d8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pytest_odoo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import ast
88
import os
99
import signal
10+
import subprocess
1011
import threading
1112
from contextlib import contextmanager
1213
from unittest import mock
@@ -138,16 +139,16 @@ def _worker_db_name():
138139
try:
139140
if xdist_worker:
140141
db_name = f"{original_db_name}-{xdist_worker}"
141-
os.system(f"dropdb {db_name} --if-exists")
142-
os.system(f"createdb -T {original_db_name} {db_name}")
142+
subprocess.run(["dropdb", db_name, "--if-exists"], check=True)
143+
subprocess.run(["createdb", "-T", original_db_name, db_name], check=True)
143144
odoo.tools.config["db_name"] = db_name
144145
odoo.tools.config["dbfilter"] = f"^{db_name}$"
145146
with _shared_filestore(original_db_name, db_name):
146147
yield db_name
147148
finally:
148149
if db_name != original_db_name:
149150
odoo.sql_db.close_db(db_name)
150-
os.system(f"dropdb {db_name}")
151+
subprocess.run(["dropdb", db_name, "--if-exists"], check=True)
151152
odoo.tools.config["db_name"] = original_db_name
152153
odoo.tools.config["dbfilter"] = f"^{original_db_name}$"
153154

0 commit comments

Comments
 (0)