pytest fails to ignore warnings from netCDF4 C-level Warnings #11304
Labels
status: needs information
reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Unsure if this is a bug or a known issue/limitation, or just something I am doing incorrectly, but I will list as a bug for now. I use pytest in the CI for my project (works very well for us), and we currently have our warnings filtered to errors so we will catch any warnings in the tests. Naturally, it is then important that we can ignore the warnings that are hard for us to avoid but we know are benign. The
RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility
is one such warning that often can arise but is benign in most cases . So, we want to ignore this warning. However, at least in the case of thenetCDF4
package, when this warning is raised, it is NOT raised directly from python code, but rather from a python binding inside C code (this specific warning is raised in this file here around line 52657, which I re-paste here for convience:in our setup.cfg, I have it set to filter warnings to errors, but to ignore warnings from the netCDF4 package:
however, when I attempt to run
pytest
, I still get an error during theconftest.py
when this package is loaded in:It seems to me that this means that if a warning is raised from C-level code, pytest (or
warnings
, I don't know exactly how you handle the warnings filtering) cannot detect it as warning from a specific module, and will therefore allow it past.I will note that if I change my setup.cfg filterwarnings block to instead block ALL RuntimeWarnings:
I can run fine without error, so it probably is something to do with filterwarnings being unable to realize that the warning is coming from the
netCDF4
module, maybe because it is being raised in C code.pip list
from the virtual environment you are usingpytest 7.4.0
OS: Windows Subsystem for Linux, Ubuntu 20.04
I have not recreated this with a minimal example yet but will update once I do
The text was updated successfully, but these errors were encountered: