44

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.

PyCharm unittest config

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:

PyCharm unittest results

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.

juliocesar
  • 5,706
  • 8
  • 44
  • 63
  • 1
    I think it would be helpful if you add exactly what error messages you got, also good to specify which version of PyCharm you are using. For example documentation for configuring PyCharm 4.0.4 is here https://www.jetbrains.com/pycharm/help/run-debug-configuration-python-unit-test.html#d388270e118 As a quick thought, I don't think database connection is something you have to configure inside PyCharm, and what do you mean by "other parameters" is not clear either. You may start getting down votes if you don't clarify these. – rineez Apr 24 '15 at 10:28
  • Thanks, I added relevant info to clarify it – juliocesar Apr 24 '15 at 14:53
  • Have you been able to solve this yourself? – rineez May 04 '15 at 05:48
  • No. No solutions yet – juliocesar May 04 '15 at 05:51
  • "from openerp.tests.common import TransactionCase" so need a db parameter for working with module. Open connection with "None" ofcourse returned a "False" dbname. – dsgdfg Dec 30 '15 at 08:33

2 Answers2

3

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/

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
Yacine Bs
  • 182
  • 1
  • 13
1

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.

malana
  • 5,045
  • 3
  • 28
  • 41
Sanju
  • 1,974
  • 1
  • 18
  • 33
  • I set this path, but I think the problem is not about paths (it finds modules and functions), the problem is to specify to run `openerp-server` script and specify its parameters like `database`, `db_user`, etc – juliocesar Jun 17 '15 at 22:29