camptocamp / pytest-odoo

pytest plugin to run Odoo tests
GNU Affero General Public License v3.0
70 stars 46 forks source link

ModuleNotFoundError: No module named 'odoo.addons.tiny_apps' #45

Open odoo-sh opened 2 years ago

odoo-sh commented 2 years ago

Hello,

Trying to run a test per module using cmd but getting import errors. any idea? pytest --odoo-config=/odoo/conf/odoo.cfg --odoo-database=testdb --odoo-log-level=debug --junitxml=junit-report.xml -s /odoo/src/tiny_apps/tiny_apps/purchase_batch_order

odoo@review-develop-3zknud:~$ pytest --odoo-config=/odoo/conf/odoo.cfg --odoo-database=lasgdb --odoo-log-level=debug --junitxml=junit-report.xml -s /odoo/src/tiny_apps/tiny_apps/purchase_batch_order 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: "odoo.http.rpc.request:INFO" 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: "odoo.http.rpc.response:INFO" 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: ":INFO" 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: "odoo:DEBUG" 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: "odoo.sql_db:INFO" 2022-02-28 15:19:29,231 450 DEBUG ? odoo.netsvc: logger level set: "longpolling:WARNING" 2022-02-28 15:19:29,434 450 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf 2022-02-28 15:19:29,438 450 INFO ? odoo.addons.base.models.ir_actions_report: Wkhtmltopdf seems to be broken. 2022-02-28 15:19:29,575 450 INFO ? odoo.service.server: HTTP service (werkzeug) running on 0.0.0.0:9069 2022-02-28 15:19:29,576 450 INFO ? odoo.service.server: Stopping gracefully ================================================================================ test session starts ================================================================================= platform linux -- Python 3.7.12, pytest-7.0.1, pluggy-0.13.1 rootdir: /odoo plugins: cov-3.0.0, odoo-0.7.1 collected 0 items / 1 error

======================================================================================= ERRORS ======================================================================================= __ ERROR collecting src/tiny_apps/tiny_apps/purchase_batch_order/tests/test_batch_order.py ___ .local/lib/python3.7/site-packages/pytest_odoo.py:140: in _importtestmodule import(modname) E ModuleNotFoundError: No module named 'odoo.addons.tiny_apps' ------------------------------------------------------------------ generated xml file: /home/odoo/junit-report.xml ------------------------------------------------------------------- ============================================================================== short test summary info =============================================================================== ERROR ../../odoo/src/tiny_apps/tiny_apps/purchase_batch_order/tests/test_batch_order.py - ModuleNotFoundError: No module named 'odoo.addons.tiny_apps' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ================================================================================== 1 error in 0.20s ==================================================================================

Jerther commented 2 years ago

Try adding the -v argument. I had a similar problem a month ago and this fixed it, for some reason...

simahawk commented 2 years ago

Are you sure the module is installed? Can you run tests w/ std odoo command? odoo -d XXX -i $mod_name --stop-after-init --test-enable?

odoo-sh commented 2 years ago

Hello,

yes, the module is installed as you can see in runtest.log

We are executing pytest at first followed by odoo --test-enable. runtests.log

UPDATE: the run test with standard odoo command succeed.

simahawk commented 2 years ago

Are you sure tests are running w/ odoo? Do you import your test file in tests/__init__.py? Bear in mind that if this is not the case, pytest will find it, odoo won't. Very likely you have a problem on an import.

odoo-sh commented 2 years ago

yes. we did import our testfile in tests/__init__.py odoo -d xxx -i $mod_name --stop-after-init --test-enable succeed.

As a workaround we changed the following and it worked.

Commented line 122:  pkgroot = pypkgpath.dirpath()
Changed line 124:   
names = self.fspath.new(ext="").relto(pkgroot).split(sep)
To
names = self.fspath.new(ext="").relto(pypkgpath).split(sep)
simahawk commented 2 years ago

ok, but the fact that I see no module named 'odoo.addons.tiny_apps' makes me think you have a problem. AFAIS tiny_apps is a folder and not and addon. However is a bit hard to judge w/out knowing your setup.

odoo-sh commented 2 years ago

yes tiny_apps is a folder. we have addons_path=... , /odoo/src/tiny_apps/tiny_apps, ..... tiny_apps folder has many modules with test. We want to run pytest for selective modules.

idadzie commented 2 years ago

@odoo-sh export the OPENERP_SERVER environment variable

In terminal

export OPENERP_SERVER=/path/to/odoo.cfg

or in your bashrc or zshrc file append

export OPENERP_SERVER=/path/to/odoo.cfg

and reload the shell with exec $SHELL