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

Support odoo>=18.0 #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

petrus-v
Copy link
Contributor

@petrus-v petrus-v commented Oct 19, 2024

Avoid logging error/warning on: fix 2/3 topic of #79 (you needs this PR to make is works odoo/odoo#184409)

  • In odoo 18 if we load odoo.tests.common before setting test_enable=True we get a logging error which is very noisy while developing. ie :
pytest --odoo-database db-test odoo/addons/ --ff --sw
Importing test framework, avoid importing from business modules and when not running in test mode
Stack (most recent call last):
  File "~/.venv/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 201, in console_main
    code = main()
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 156, in main
    config = _prepareconfig(args, plugins)
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 341, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "~/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "~/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "~/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1140, in pytest_cmdline_parse
    self.parse(args)
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1494, in parse
    self._preparse(args, addopts=addopts)
  File "~/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 1381, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "~/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/home/pverkest/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/importlib/metadata/__init__.py", line 205, in load
    module = import_module(match.group('module'))
  File "/home/pverkest/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "~/src/pytest-odoo/pytest_odoo.py", line 22, in <module>
    import odoo.tests
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "~/src/ocb/odoo/tests/__init__.py", line 8, in <module>
    from . import common
  File "<frozen importlib._bootstrap>", line 1415, in _handle_fromlist
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "~/src/ocb/odoo/tests/common.py", line 98, in <module>
    _logger.error(
================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.12.6, pytest-8.3.3, pluggy-1.5.0
rootdir: ~
configfile: pyproject.toml
plugins: odoo-2.1.1
collected 2 items                                                                                                                                                                                                                                                                        
run-last-failure: rerun previous 1 failure first
stepwise: skipping 0 already passed items.

bacause of this code https://github.com/odoo/odoo/blob/18.0/odoo/tests/common.py#L93-L101

_logger = logging.getLogger(__name__)
if config['test_enable'] or config['test_file']:
    _logger.info("Importing test framework", stack_info=_logger.isEnabledFor(logging.DEBUG))
else:
    _logger.error(
        "Importing test framework"
        ", avoid importing from business modules and when not running in test mode",
        stack_info=True,
    )
  • second point is a warning displayed while opening the registry
 /.venv/lib/python3.12/site-packages/pytest_odoo.py:167: DeprecationWarning: Use directly odoo.modules.registry.Registry
    odoo.registry(db_name)

because this registry method becomes deprecated https://github.com/odoo/odoo/blob/18.0/odoo/__init__.py#L37 we can safely use the Registry as this method do because we are setting the database and this code hasn't change from odoo v10.0

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@f602202). Learn more about missing BASE report.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master      #80   +/-   ##
=========================================
  Coverage          ?   33.33%           
=========================================
  Files             ?        1           
  Lines             ?      117           
  Branches          ?        0           
=========================================
  Hits              ?       39           
  Misses            ?       78           
  Partials          ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@petrus-v
Copy link
Contributor Author

tested against odoo 18.0 and 14.0 real projects

@petrus-v petrus-v marked this pull request as ready for review October 19, 2024 14:49
Registry class is present and signature does change since v10.0
@petrus-v petrus-v changed the title Avoid error on odoo>=18 removing useless import Avoid logging error/warning on odoo>=18.0 Oct 19, 2024
@petrus-v petrus-v changed the title Avoid logging error/warning on odoo>=18.0 Support odoo>=18.0 Oct 19, 2024
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

Successfully merging this pull request may close these issues.

2 participants