question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't filter ImportWarning during tests run

See original GitHub issue

I tried setting this config:

[pytest]
filterwarnings =
    ignore::Warning
    ignore::ImportWarning

Running as docker-compose run --rm odoo pytest -s --odoo-database=odoodb my/path/to/test

ignore::Warning ignores all exceptions, except ImportWarning. Not sure why. ignore::ImportWarning does nothing.

I get:

2022-10-30 07:11:57,869 1 WARNING ? py.warnings: <frozen importlib._bootstrap>:914: ImportWarning: AddonsHook.find_spec() not found; falling back to find_module()
  File "/opt/odoo/venv/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 190, in console_main
    code = main()
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 167, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/main.py", line 317, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/main.py", line 266, in wrap_session
    config._do_configure()
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1037, in _do_configure
    self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 277, in call_historic
    res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/opt/odoo/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/opt/odoo/venv/lib/python3.10/site-packages/_pytest/faulthandler.py", line 27, in pytest_configure
    import faulthandler

Ubuntu 22.04 (docker image)

platform linux -- Python 3.10.6, pytest-7.2.0, pluggy-1.0.0
rootdir: /opt/odoo, configfile: pytest.ini
plugins: odoo-0.8.1.dev1+g98f01ca
collected 7 items 

pip list:

Package            Version
------------------ ---------------------
Package            Version
------------------ ---------------------
anthem             0.13.1.dev18+g46a07a2
appdirs            1.4.4
attrs              22.1.0
Babel              2.9.1
beautifulsoup4     4.11.1
build              0.9.0
cached-property    1.5.2
certifi            2022.9.24
cffi               1.15.1
chardet            3.0.4
click              8.1.3
click-odoo         1.6.0
click-odoo-contrib 1.16.0
cryptography       3.4.8
decorator          4.4.2
defusedxml         0.7.1
docutils           0.16
ebaysdk            2.1.5
exceptiongroup     1.0.0
freezegun          0.3.15
future             0.18.2
gevent             21.8.0
greenlet           1.1.2
idna               2.8
iniconfig          1.1.1
isodate            0.6.1
Jinja2             2.11.3
libsass            0.18.0
lxml               4.6.5
manifestoo_core    0.10.2
marabunta          0.10.6
maraplus           0.3.0
MarkupSafe         1.1.0
mergedeep          1.3.4
num2words          0.5.6
ofxparse           0.21
packaging          21.3
passlib            1.7.3
pep517             0.13.0
pexpect            4.8.0
Pillow             9.0.1
pip                22.0.2
pip-tools          6.9.0
pluggy             1.0.0
polib              1.1.0
psutil             5.6.7
psycopg2           2.8.6
ptyprocess         0.7.0
pyasn1             0.4.8
pyasn1-modules     0.2.8
pycparser          2.21
pydot              1.4.1
pyOpenSSL          19.0.0
pyparsing          3.0.9
PyPDF2             1.26.0
pyserial           3.4
pytest             7.2.0
pytest-odoo        0.8.1.dev1+g98f01ca
python-dateutil    2.7.3
python-ldap        3.4.0
python-stdnum      1.13
pytz               2019.3
pyusb              1.0.2
PyYAML             6.0
qrcode             6.1
reportlab          3.5.59
requests           2.25.1
requests-toolbelt  0.10.1
ruamel.yaml        0.17.21
ruamel.yaml.clib   0.2.7
setuptools         59.6.0
six                1.16.0
soupsieve          2.3.2.post1
tomli              2.0.1
unicodecsv         0.14.1
urllib3            1.26.5
vobject            0.9.6.1
watchdog           2.1.9
Werkzeug           2.0.2
wheel              0.37.1
xlrd               1.2.0
XlsxWriter         1.1.2
xlwt               1.3.0
zeep               3.4.0
zope.event         4.5.0
zope.interface     5.5.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
akhilramkeecommented, Nov 1, 2022

Could it be that ImportWarning is getting thrown in pytest_configure ?

If so, it looks to be related to warnings filter not respected in pytest_configure - https://github.com/pytest-dev/pytest/issues/10128

0reactions
oerp-odoocommented, Nov 5, 2022

As a workaround, to suppress such warnings from Odoo, it is possible to use this kind of option in Odoo config:

log_handler = :INFO,py.warnings:ERROR

Because its a WARNING, if we set higher level, it will be ignored. Currently don’t see cleaner way to workaround it without changing Odoo code…😃

Though, of course it will filter all py.warnings

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to suppress ImportWarning in a python unittest script
A simpler solution is to define the warnings filter inside unittest's setUp() method, which is run right before each test. import unittest class ......
Read more >
Unable to filter Warning raised from another pytest plugin with ...
As these were not a reason to concern, we used filterwarning inside pytest.ini in order to catch and remove them when running tests....
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
The order in which the various tests will be run is determined by sorting the test method names with respect to the built-in...
Read more >
How to capture warnings — pytest documentation
Starting from version 3.1 , pytest now automatically catches warnings during test execution and displays them at the end of the session:.
Read more >
Review test results - Azure Pipelines | Microsoft Learn
All of the filter criteria are cumulative in nature. Filter large test result set. Additionally, with multiple Grouping options such as Test run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found