pytest-odoo icon indicating copy to clipboard operation
pytest-odoo copied to clipboard

Can't run inside Eclipse

Open Jerther opened this issue 8 years ago • 3 comments

Hey, I'm really glad I found your plugin! And it works flawlessly in a terminal.

Now I'd like to use it with Eclipse's py.test runner. I tried (too) many things and I always end up with this:

============================= test session starts ==============================
platform linux2 -- Python 2.7.12, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: /home/xxx/git/odoo, inifile: 
plugins: odoo-0.2.1
collecting ... collected 0 items / 1 errors

==================================== ERRORS ====================================
________ ERROR collecting addons_test/openacademy/tests/test_session.py ________
File "/usr/lib/python2.7/site-packages/pytest_odoo.py", line 84
in _importtestmodule
    __import__(modname)
E   ImportError: No module named openacademy.tests.test_session
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.22 seconds ============================

I have this hierarchy:

odoo
- addons_test
    - openacademy
      - __init__.py
      - models.py
      - tests
        - __init__.py
        - test_session.py

I can run pytest -v in a terminal and it works fine, but not if I do Ctrl+F9 in test_session.py in eclipse.

Any clue? Thanks :)

Jerther avatar Jan 26 '17 18:01 Jerther

Finally got it to work.

  • Either ensure the module folder is a project in PyDev Workspace, or add a conftest.py file in the addons directory. (ref: here )
  • There are two lines of code in pytest_odoo.py that change the module name in case they are not in openerp.addon. I commented them out:
#if not modname.startswith(odoo_namespace + '.addons.'):
#    modname = odoo_namespace + '.addons.' + modname
  • Set the OPENERP_SERVER variable in /etc/environment (requires logout-login to take effect): OPENERP_SERVER=/home/RickTom/git/odoo/addons_test/openerp-server.conf

At this point, the tests launch fine from eclipse, but the process hangs. I dug in and found out why: here. I don't like to modify odoo code, but I went ahead anyway. I made the following small modifications in odoo/openerp/service/server.py

Add this under class ThreadedServer(CommonServer): initial_threads = []

And add this in the init method:

def __init__(self, app):
    for t in threading.enumerate():
        self.initial_threads.append(t)

Then modify the condition in the stop() method of the same class so it looks like this: if thread != me and not thread.isDaemon() and thread.ident != self.main_thread_id and thread not in self.initial_threads:

And it works:

image

Now even though this works, I'm quite new to Odoo and Python unit testing so I'm not fully aware of all the consequences.

Jerther avatar Feb 27 '17 20:02 Jerther

About the two lines I removed in pytest_odoo.py: it appears I needed to remove them for Odoo 8, but they are needed for Odoo 10 (and maybe 9 too)

Jerther avatar Apr 24 '17 16:04 Jerther

How could I run the same in Eclipse?

techsbone avatar Jan 09 '18 06:01 techsbone