我尝试为odoo模块编写测试。 模块具有以下结构:
/pr_mobile
|--->conttrollers
|--->demo
|--->models
|--->security
|--->tests
....|----> __init__.py
....|----> test_mobileproduct.py
|--->views
__init__.py
...
初始化 .py:
from . import tests
测试/ 初始化 .py
import test_mobileproduct
tests / test_mobileproduct.py
# -*- coding: utf-8 -*-
import unittest
from openerp.tests import common
from openerp.exceptions import ValidationError
class TestMobileProduct(common.TransactionCase):
def test_get_maket(self):
self.assertEqual(1, 2)
def test_get_maket2(self):
self.assertEqual(1, 2)
def test_get_maket3(self):
self.assertEqual(1, 2)
def test_get_maket4(self):
self.assertEqual5(1, 2)
if __name__ == '__main__':
unittest.main()
我使用以下命令进行测试:
./ odoo.py --addons-path = addons,openerp / addons,openerp / my-addons -d pr_odoo_v9 --db-filter =“ ^ pr_odoo_v9” -u pr_mobile --test-enable --log-level = test
结果是:
skif@ubuntu-desktop:/opt/odoo$ ./odoo.py --addons-path=addons,openerp/addons,openerp/my-addons -d pr_odoo_v9 --db-filter="^pr_odoo_v9" -u pr_mobile --test-enable --log-level=test
2019-04-10 15:11:48,708 8919 INFO ? openerp: OpenERP version 9.0c
2019-04-10 15:11:48,709 8919 INFO ? openerp: addons paths: ['/home/skif/.local/share/Odoo/addons/9.0', u'/opt/odoo/addons', u'/opt/odoo/openerp/addons', u'/opt/odoo/openerp/my-addons']
2019-04-10 15:11:48,709 8919 INFO ? openerp: database: default@default:default
2019-04-10 15:11:48,774 8919 INFO ? openerp.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069
2019-04-10 15:11:48,780 8919 INFO pr_odoo_v9 openerp.modules.loading: loading 1 modules...
2019-04-10 15:11:48,788 8919 INFO pr_odoo_v9 openerp.modules.loading: 1 modules loaded in 0.01s, 0 queries
2019-04-10 15:11:49,541 8919 INFO pr_odoo_v9 openerp.modules.loading: loading 64 modules...
2019-04-10 15:11:49,560 8919 INFO ? openerp.addons.bus.models.bus: Bus.loop listen imbus on db postgres
2019-04-10 15:11:49,579 8919 INFO pr_odoo_v9 openerp.addons.report.models.report: You need Wkhtmltopdf to print a pdf version of the reports.
2019-04-10 15:11:50,252 8919 INFO pr_odoo_v9 openerp.modules.module: module pr_mobile: creating or updating database tables
/opt/odoo/openerp/models.py:451: UnicodeWarning: Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if cols[k][key] != vals[key]:
2019-04-10 15:11:50,601 8919 INFO pr_odoo_v9 openerp.modules.loading: loading pr_mobile/views/views.xml
2019-04-10 15:11:50,970 8919 INFO pr_odoo_v9 openerp.modules.loading: loading pr_mobile/views/saleorder.xml
2019-04-10 15:11:51,017 8919 INFO pr_odoo_v9 openerp.modules.loading: loading pr_mobile/views/templates.xml
2019-04-10 15:11:51,021 8919 INFO pr_odoo_v9 openerp.addons.base.ir.ir_translation: module pr_mobile: no translation for language ru
2019-04-10 15:11:51,171 8919 INFO pr_odoo_v9 openerp.modules.loading: 64 modules loaded in 1.63s, 5 queries
2019-04-10 15:11:51,626 8919 INFO pr_odoo_v9 openerp.modules.loading: Modules loaded.
2019-04-10 15:11:51,628 8919 INFO pr_odoo_v9 openerp.modules.loading: All post-tested in 0.00s, 0 queries
为什么测试没有运行?在db中,显示来自生产服务器的数据。
答案 0 :(得分:0)
您必须设置at_install
或post_install
才能使测试在安装或升级时运行
class TestMobileProduct(common.TransactionCase):
at_install = True
post_install = True