I can run unit tests of my OpenERP v7 add-on as described here.
In PyCharm I did it by adding a Python configuration in Run/Debug Configuration as follows:
Script:
/home/juliocesar/work/projects/my_project/openerp-server
Script parameters:
--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
It runs successfully but shows a standard output in text log format like the following:
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
where it shows the results of run the following test I created in add-on my_addon
of project my_project
, in /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()
What I want is to use Python tests -> Unittest configuration to display tests output with red/green icons and PyCharm interface for tests results.
Unittest configuration requires the script file where tests are located, if I specify the file, PyCharm finds all tests in the file but gives errors because the database (and other parameters like openerp-server
script and the rest parameters specified in above to run OpenERP tests) is not configured:
This is the result of running this 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
So, how to specify the required parameters to run OpenERP v7 unittest with a PyCharm test configuration?
I used PyCharm 4.0.6 Build #PY-139.1659, but it also doesn't works in PyCharm 5.
Run or debug a testPress Alt+Shift+F10 to see the list of available run configurations or Alt+Shift+F9 for debug configurations. to the right of the list. Alternatively, select Run | Run Shift+F10 or Run | Debug Shift+F9 from the main menu.
Simply click the Toggle auto-run in the test tool window, then run your tests once.
You can debug using cmd
in windows enter with cmd into odoo.exe folder C:\Program Files (x86)\Odoo 8.0-20150719\server
and execute this command
odoo --log-level=debug
or terminal in Linux enter with terminal into odoo.py file (/usr/bin/) and execute this command
python odoo.py --log-level=debug
tape ctrl+z or ctrl+c to desactivate a log .
You will find a file (openerp-server.log) in /var/log/odoo/
In the run/debug window did you set the value of the current working directory field to /home/juliocesar/work/projects/my_project
? This would help PyCharm to look for the relative paths as well as the imports.
You can also try giving full path to your addons in the argument list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With