def pytest_cmdline_main(config):
if (config.getoption('--odoo-database')
or os.environ.get('OPENERP_SERVER')):
options = []
# Replace --odoo-<something> by --<something> and prepare the argument
# to propagate to odoo.
for option in ['--odoo-database', '--odoo-log-level']:
value = config.getoption(option)
if value:
odoo_arg = '--%s' % option[7:]
options.append('%s=%s' % (odoo_arg, value))
odoo.tools.config.parse_config(options)
if not odoo.tools.config['db_name']:
# if you fall here, it means you have OPENERP_SERVER pointing
# to a configuration file without 'database' configuration
raise Exception(
"please provide a database name in the Odoo configuration file"
)
odoo.service.server.start(preload=[], stop=True)
# odoo.service.server.start() modifies the SIGINT signal by its own
# one which in fact prevents us to stop anthem with Ctrl-c.
# Restore the default one.
signal.signal(signal.SIGINT, signal.default_int_handler)
with odoo.api.Environment.manage():
yield
else:
yield
评论列表
文章目录