camptocamp / pytest-odoo

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

Help me to fix "AttributeError: module 'odoo' has no attribute 'tests'" #32

Closed samsagaz closed 4 years ago

samsagaz commented 4 years ago

First of all, thanks for this pytest plugin. i want to know if someome know why i cant use it in my machine :/

Im using Odoo12 and Python3.8

test is

class TestBase: def test_config(self): assert 1 == 2

error

___ ERROR at setup of TestBase.test_config ___

@pytest.fixture(scope='session', autouse=True)
def load_registry():
    # Initialize the registry before running tests.
    # If we don't do that, the modules will be loaded *inside* of the first
    # test we run, which would trigger the launch of the postinstall tests
    # (because we force 'test_enable' to True and the at end of the loading of
    # the registry, the postinstall tests are run when test_enable is enabled).
    # And also give wrong timing indications.
    # Finally we enable `testing` flag on current thread
    # since Odoo sets it when loading test suites.
    threading.currentThread().testing = True
  odoo.registry(odoo.tests.common.get_db_name())

E AttributeError: module 'odoo' has no attribute 'tests'

/home/user/.virtualenvs/odoo/lib/python3.8/site-packages/pytest_odoo.py:89: AttributeError

as you can see im running the instance inside a virtualenv

guewen commented 4 years ago

Hi @samsagaz,

I never tried with python 3.8, could you check if you have the same issue with for instance 3.7?

Another issue could be the way odoo is installed into your virtualenv, how did you install it? (should work with pip install -e path/to/odoo)

You could try to put a pdb.set_trace() just before the line odoo.registry(odoo.tests.common.get_db_name()) and inspect what is odoo there.

samsagaz commented 4 years ago

Hi @guewen i installed odoo using pip install -e . (in my odoo path) after that i get another error.

__ ERROR collecting working-addons/custom_stock/tests/test_base_cases.py ___ ../../../../.virtualenvs/citrux/lib/python3.8/site-packages/pytest_odoo.py:137: in _importtestmodule import(modname) odoo/modules/module.py:61: in load_module f, path, (_suffix, mode, type) = imp.find_module(addon_name, ad_paths) ../../../../.virtualenvs/citrux/lib/python3.8/imp.py:296: in find_module raise ImportError(_ERR_MSG.format(name), name=name) E ImportError: No module named 'custom_stock' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ===================================================================================================================== 1 error in 0.17s =====================================================================================================================

the only way to get it working is just to copy my custom_stock module inside my_odoo_root/odoo/addons/custom_stock :/

guewen commented 4 years ago

Seems like your addons_path option is not set correctly. You can either provide a configuration file with an addons path that contains your module, either install your module with pip -e install as well (you'll need to generate setuptools files beforehand with setuptools-odoo-make-default -d . using https://pypi.org/project/setuptools-odoo). This is not related to pytest-odoo, you'll have the same requirement to start your server.