我可以按照here所述运行我的OpenERP v7插件的单元测试。
在 PyCharm 中,我通过在运行/调试配置中添加Python配置来实现,如下所示:
脚本:
/home/juliocesar/work/projects/my_project/openerp-server
脚本参数:
--addons-path=openerp/addons,openerp/addons/my_addons
--log-level=test
--database=my_project_db_test
--db_host=localhost
--db_user=test
--db_password=123
--init=my_addon
--test-enable
--stop-after-init
它成功运行但以文本日志格式显示标准输出,如下所示:
2015-04-24 13:47:55,101 12340 TEST my_project openerp.modules.module: module my_addon: executing 1 `fast_suite` and/or `checks` sub-modules
2015-04-24 13:47:55,101 12340 TEST my_project openerp.modules.module: test_change_old_received_to_contingency (openerp.addons.my_addon.tests.test_my_addon.TestMyItems)
2015-04-24 13:47:55,101 12340 TEST my_project openerp.modules.module: ` Test patch to change old received status to contingency.
2015-04-24 13:47:55,110 12340 TEST my_project openerp.modules.module: Ran 1 tests in 0.006s
2015-04-24 13:47:55,110 12340 TEST my_project openerp.modules.module: OK
在其中显示运行我在项目my_addon
的加载项my_project
中创建的以下测试的结果,位于/home/juliocesar/work/projects/my_project/openerp/addons/my_addon/tests/test_my_addon.py
:
from openerp.tests.common import TransactionCase
import unittest2
class TestMyItems(TransactionCase):
def test_change_old_received_to_contingency(self):
"""Test patch to change old received status to contingency."""
self.assertTrue(True)
if __name__ == '__main__':
unittest2.main()
我想要的是使用 Python测试 - > Unittest 配置,用红色/绿色图标显示测试输出,PyCharm接口显示测试结果。
单元测试配置需要测试所在的脚本文件,如果我指定文件,PyCharm会在文件中找到所有测试,但由于数据库(以及其他参数,如openerp-server
脚本和其他参数在以上运行OpenERP测试)未配置:
这是运行此配置的结果:
/usr/bin/python2.7 /home/juliocesar/apps/pycharm/helpers/pycharm/utrunner.py /home/juliocesar/work/projects/my_project/openerp/addons/my_addon/tests/ false
Testing started at 09:38 AM ...
No handlers could be found for logger "openerp.sql_db"
Process finished with exit code 0
Error
Traceback (most recent call last):
File "/home/juliocesar/work/projects/my_project/openerp/tests/common.py", line 94, in setUp
TransactionCase.cr = self.cursor()
File "/home/juliocesar/work/projects/my_project/openerp/tests/common.py", line 55, in cursor
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
File "/home/juliocesar/work/projects/my_project/openerp/modules/registry.py", line 193, in get
update_module)
File "/home/juliocesar/work/projects/my_project/openerp/modules/registry.py", line 209, in new
registry = Registry(db_name)
File "/home/juliocesar/work/projects/my_project/openerp/modules/registry.py", line 76, in __init__
cr = self.db.cursor()
File "/home/juliocesar/work/projects/my_project/openerp/sql_db.py", line 484, in cursor
return Cursor(self._pool, self.dbname, serialized=serialized)
File "/home/juliocesar/work/projects/my_project/openerp/sql_db.py", line 182, in __init__
self._cnx = pool.borrow(dsn(dbname))
File "/home/juliocesar/work/projects/my_project/openerp/sql_db.py", line 377, in _locked
return fun(self, *args, **kwargs)
File "/home/juliocesar/work/projects/my_project/openerp/sql_db.py", line 440, in borrow
result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
OperationalError: FATAL: database "False" does not exist
那么,如何使用PyCharm测试配置指定运行OpenERP v7 unittest所需的参数?
我使用了PyCharm 4.0.6 Build#PY-139.1659,但它在PyCharm 5中也不起作用。
答案 0 :(得分:2)
您可以在Windows中使用cmd进行调试 用cmd进入odoo.exe文件夹C:\ Program Files(x86)\ Odoo 8.0-20150719 \ server并执行此命令
odoo --log-level=debug
或linux中的终端 在终端输入odoo.py文件(/ usr / bin /)并执行此命令
python odoo.py --log-level=debug
tape ctrl + z或ctrl + c来取消激活日志。
你会在/ var / log / odoo /
中找到一个文件(openerp-server.log)答案 1 :(得分:1)
在运行/调试窗口中,您是否将当前工作目录字段的值设置为/home/juliocesar/work/projects/my_project
?这将有助于PyCharm寻找相对路径以及导入。
您还可以尝试在参数列表中提供插件的完整路径。