initOS / dob

Tool to bootstrap and manage Odoo instances using docker-compose
Other
17 stars 6 forks source link

How to run module tests? #5

Closed flachica closed 10 months ago

flachica commented 10 months ago

I have Odoo working with this tool perfectly. If I run the tests with this command it works correctly:

docker compose run --rm odoo odoo run --stop-after-init --test-tags /pos_default_partner --test-enable -i pos_default_partner

But when run the tests with:

docker compose run --rm odoo odoo test pos_default_partner

However, when I read the log I get the following message:

2023-11-17 16:24:33,200 1 WARNING ? py.warnings: <frozen importlib._bootstrap>:914: ImportWarning: AddonsHook.find_spec() not found; falling back to find_module()
  File "/usr/local/bin/dob", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/doblib/__main__.py", line 136, in main
    sys.exit(CIEnvironment(args.cfg).test(left))
  File "/usr/local/lib/python3.10/site-packages/doblib/ci.py", line 209, in test
    result = pytest.main()
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 169, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 493, in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 115, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 77, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 318, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/usr/local/lib/python3.10/site-packages/_pytest/main.py", line 267, in wrap_session
    config._do_configure()
  File "/usr/local/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1053, in _do_configure
    self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
  File "/usr/local/lib/python3.10/site-packages/pluggy/_hooks.py", line 514, in call_historic
    res = self._hookexec(self.name, self._hookimpls, kwargs, False)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_manager.py", line 115, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.10/site-packages/pluggy/_callers.py", line 77, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.10/site-packages/_pytest/faulthandler.py", line 25, in pytest_configure
    import faulthandler

========================= test session starts ========================= 
platform linux -- Python 3.10.13, pytest-7.4.3, pluggy-1.3.0
rootdir: /srv/odoo/odoo
plugins: odoo-1.0.0, anyio-3.7.1, cov-4.1.0
collected 0 items                                                                                                                                                     

=========================  no tests ran in 0.00s ========================= 
ERROR: file or directory not found: pos_default_partner
fkantelberg commented 10 months ago

docker compose run --rm odoo odoo test ... uses pytest under the hood and doesn't know what an Odoo module is. Using the tests using the Odoo framework Odoo does the mapping. I assume that the module is from an additional repo. In that case the modules are symlinked inside the container to /tmp/addons/... which means it would be docker compose run --rm odoo odoo test /tmp/addons/pos_default_partner. If you are also interrested in the coverage: docker compose run --rm odoo odoo test /tmp/addons/pos_default_partner --cov /tmp/addons/pos_default_partner. If you need additional filtering you can leverage the -k of pytest.

flachica commented 10 months ago

Thank you very much for responding so quickly @fkantelberg.

I have made some progress on this. To point out that the module I am trying to test is "base" which is included in standard Odoo. To rule out any problems with my local configuration

I have cloned the project into an empty directory and then run:

./setup.sh
docker compose build
docker-compose run --rm odoo odoo init 
docker-compose run --rm odoo odoo update
docker-compose up 

Following these steps Odoo starts correctly

When launching the test the system does not find it

docker-compose run --rm odoo odoo odoo test /tmp/web
reating dob_odoo_run ... done
2023-11-20 10:26:34 INFO doblib.utils: Loading configuration file
2023-11-20 10:26:34 INFO doblib.utils:  * odoo.local.yaml
2023-11-20 10:26:34 INFO doblib.utils:  * odoo.project.yaml
2023-11-20 10:26:34 INFO doblib.utils:  * odoo.default.yaml
2023-11-20 10:26:34 INFO doblib.utils:  * odoo.yaml
2023-11-20 10:26:34 INFO doblib.utils:  * defuse.yaml
2023-11-20 10:26:34 INFO doblib.utils:  * anonymize.yaml
2023-11-20 10:26:34 WARNING doblib.utils:  * odoo.versions.yaml
2023-11-20 10:26:34 INFO doblib.utils: Linking Odoo modules
2023-11-20 10:26:34,945 1 WARNING ? py.warnings: /srv/odoo/odoo/parts/odoo/odoo/tools/config.py:565: DeprecationWarning: The longpolling-port is a deprecated alias to the gevent-port option, please use the latter.
  File "/usr/local/bin/dob", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/doblib/__main__.py", line 136, in main
    sys.exit(CIEnvironment(args.cfg).test(left))
  File "/usr/local/lib/python3.8/site-packages/doblib/ci.py", line 205, in test
    config.parse_config(["-c", base.ODOO_CONFIG])
  File "/srv/odoo/odoo/parts/odoo/odoo/tools/config.py", line 378, in parse_config
    self._warn_deprecated_options()
  File "/srv/odoo/odoo/parts/odoo/odoo/tools/config.py", line 565, in _warn_deprecated_options
    warnings.warn(

2023-11-20 10:26:34,945 1 INFO ? odoo: Odoo version 16.0 
2023-11-20 10:26:34,945 1 INFO ? odoo: Using configuration file at /srv/odoo/odoo/etc/odoo.cfg 
2023-11-20 10:26:34,945 1 INFO ? odoo: addons paths: ['/srv/odoo/odoo/parts/odoo/odoo/addons', '/srv/odoo/filestore/addons/16.0', '/tmp/addons', '/srv/odoo/odoo/src/addons'] 
2023-11-20 10:26:34,945 1 INFO ? odoo: database: odoo@db:5432 
============================================================================ test session starts ============================================================================
platform linux -- Python 3.8.18, pytest-7.4.3, pluggy-1.3.0
rootdir: /srv/odoo/odoo
plugins: odoo-1.0.0, cov-4.1.0
collected 0 items                                                                                                                                                           

=========================================================================== no tests ran in 0.01s ===========================================================================
ERROR: file or directory not found: base

ERROR: 4

It strikes me that when I enter the odoo container with:

docker compose run odoo sleep 10000000

The /tmp/addons directory is empty

fkantelberg commented 10 months ago

If you use run you create a new container. The creation and linking of /tmp/addons [1] is done in various processes by the dob-lib wrapper. (basically when it's needed) If you run and bash etc. you get into a container without the linking because the wrapper never runs. If you enter a container with exec of a running Odoo or a shell you see the folder. We would need to use the entrypoint if this is necessary but there was no requirement until now. If you need the linked modules inside of a container with bash

The command is: docker-compose run --rm odoo odoo test /tmp/addons/web

The first odoo is the Odoo service defined in the docker-compose.yaml. The 2nd odoo is a small script (see the binfolder) which switches the working dir and passed the arguments to dob-lib. --rm to remove the container after usage.

If I need a bash with the modules linked I go into the bash with run. Start odoo shell shortly and close it.

[1] linking source

flachica commented 10 months ago

Great response. You solved my problem, as well as, clarified many points of the project lifecycle. I am very grateful.