Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run inside Eclipse #2

Open
Jerther opened this issue Jan 26, 2017 · 3 comments
Open

Can't run inside Eclipse #2

Jerther opened this issue Jan 26, 2017 · 3 comments

Comments

@Jerther
Copy link

Jerther commented Jan 26, 2017

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
Copy link
Author

Jerther commented Feb 27, 2017

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
Copy link
Author

Jerther commented Apr 24, 2017

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)

@techsbone
Copy link

How could I run the same in Eclipse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants