I'm writing some tests for code that calls TensorFlow 2.0.1. This library imports the imp module, which triggers a deprecation warning when I run pytest. I'm trying to muffle this warning, but without success.
This is my testing module:
import pytest
import warnings
from fclib.models.dilated_cnn import create_dcnn_model
def test_create_dcnn_model():
with pytest.deprecated_call():
create_dcnn_model(seq_len=1, max_cat_id=[30, 120]) # calls tensorflow.keras code
The output from pytest test_dcnn.py
is
[...]
======================================== FAILURES ========================================
_________________________________ test_create_dcnn_model _________________________________
def test_create_dcnn_model():
with pytest.deprecated_call():
> create_dcnn_model(seq_len=1, max_cat_id=[30, 120])
E Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>, <class 'PendingDeprecationWarning'>) was emitted. The list of emitted warnings is: [].
fclib/tests/test_dcnn.py:11: Failed
---------------------------------- Captured stderr call ----------------------------------
2020-07-07 03:15:03.162833: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2020-07-07 03:15:03.174538: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2095190000 Hz
2020-07-07 03:15:03.177318: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55ef3370ff20 executing computations on platform Host. Devices:
2020-07-07 03:15:03.177351: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
==================================== warnings summary ====================================
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================ short test summary info =================================
FAILED fclib/tests/test_dcnn.py::test_create_dcnn_model - Failed: DID NOT WARN. No warn...
============================== 1 failed, 1 warning in 2.39s ==============================
So it complains that there was no warning, and yet the printed output says that there was a warning. What's happening here?
If I remove the with pytest.deprecated_call()
line, I get:
def test_create_dcnn_model():
# with pytest.deprecated_call():
create_dcnn_model(seq_len=1, max_cat_id=[30, 120])
================================== test session starts ===================================
platform linux -- Python 3.6.10, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /data/forecasting/fclib
collected 1 item
fclib/tests/test_dcnn.py . [100%]
==================================== warnings summary ====================================
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/latest/warnings.html
============================== 1 passed, 1 warning in 2.00s ==============================
So it passes, but the warning message is still present. How can I get rid of that message completely?