pytest: Can't filter ImportWarning during tests run

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

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