运行OpenERP 7在PyCharm进行testing
我可以运行我的OpenERP v7加载项的unit testing,如下所述。
在PyCharm中,我通过在运行/debuggingconfiguration中添加了一个Pythonconfiguration,如下所示:
脚本:
/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
它显示了运行以下testing的结果,我在项目my_project
附加项my_addon
中创build了/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()
我想要的是使用Pythontesting – >unit testingconfiguration显示testing输出与红色/绿色图标和PyCharm接口testing结果。
unit testingconfiguration需要testing所在的脚本文件,如果我指定文件,PyCharm会查找文件中的所有testing,但会给出错误,因为数据库(和其他参数,如openerp-server
脚本和其他参数,如上面指定的运行OpenERPtesting)未configuration:
这是运行此configuration的结果:
/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
那么,如何使用PyCharmtestingconfiguration来指定运行OpenERP v7 unittest所需的参数呢?
我使用PyCharm 4.0.6 Build#PY-139.1659,但它也不能在PyCharm 5中工作。
在运行/debugging窗口中,您是否将当前工作目录字段的值设置为/home/juliocesar/work/projects/my_project
? 这将帮助PyCharm寻找相对path以及import。
您也可以尝试在参数列表中给出您的插件的完整path。
你可以在Windows下使用cmd进行debugging,inputcmd到odoo.exe文件夹C:\ Program Files(x86)\ Odoo 8.0-20150719 \ server并执行这个命令
odoo --log-level=debug
或linuxterminalinputodoo.py文件(/ usr / bin /)并执行此命令
python odoo.py --log-level=debug
磁带ctrl + z或ctrl + c来取消激活日志。
你会发现一个文件(openerp-server.log)在/ var / log / odoo /