[python] 運行OpenERP 7在PyCharm進行測試



Answers

你可以在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

磁帶ctrl + z或ctrl + c來取消激活日誌。

你會發現一個文件(openerp-server.log)在/ var / log / odoo /

Question

我可以運行我的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_project附加項my_addon中創建了/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測試 - >單元測試配置顯示測試輸出與紅色/綠色圖標和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中工作。




Links