pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.85k stars 2.64k forks source link

Setting "error" in filterwarnings in `pyproject.toml` silences specific warning #11483

Closed tcrasset closed 10 months ago

tcrasset commented 11 months ago

Hello! :wave:

Specifying "error" at the top of the filterwarnings list in pyproject.toml silences a warning, while I expected it to be raised as an error. It raised the warning for other warnings, I don't understand why it doesn't work for that particular warning. Could you give me some instructions as to how to track down the problem? I already disabled every plugin I could. I am aware that this is not a minimal reproducible example as I figure that this a bug in my configuration.

By commenting "error" in filterwarnings, I do get the warning.

[tool.pytest.ini_options]
addopts = "--tb=short"
filterwarnings = [
    #"error",
    "ignore::pytest.PytestUnraisableExceptionWarning",
    "ignore:distutils Version:DeprecationWarning",
    "ignore:has conflict with protected namespace:UserWarning:pydantic",
    "ignore:Deprecated call to `pkg_resources\\.declare_namespace\\('.*'\\):DeprecationWarning",
    "ignore::DeprecationWarning:google.rpc",
    "ignore:Format strings passed to MaskedConstant are ignored:FutureWarning:seaborn",
    "ignore:np.find_common_type is deprecated:DeprecationWarning", # TODO: Remove this once we migrate to pandas v2
]
# asyncio_mode="strict"
❯ DOTENV=.env.test SECRETS_DIR=../.secrets poetry run pytest api/service/report_test.py  -k test_create_images_with_missing -p no:celery -p no:xdist -p no:asyncio -p no:doubles -p no:cov -p no:anyio -p no:faker -p no:hypothesispytest -p no:subtests -p no:xdist -p no:schemathesis
======================================== test session starts =========================================
platform linux -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /home/tom/Documents/dev/octopize/avatar/platform/api
configfile: pyproject.toml
plugins: mock-3.11.1
collected 23 items / 22 deselected / 1 selected                                                      

api/service/report_test.py .                                                                   [100%]

========================================== warnings summary ==========================================
api/service/report_test.py::test_create_images_with_missing
  /home/tom/.cache/pypoetry/virtualenvs/api-1Bf64r6x-py3.9/lib/python3.9/site-packages/numpy/ma/extras.py:617: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    scl = avg.dtype.type(a.count(axis))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================ 1 passed, 22 deselected, 1 warning in 1.98s =============================

Uncommenting it just silences it instead of raising it.

[tool.pytest.ini_options]
addopts = "--tb=short"
filterwarnings = [
    "error",
    "ignore::pytest.PytestUnraisableExceptionWarning",
    "ignore:distutils Version:DeprecationWarning",
    "ignore:has conflict with protected namespace:UserWarning:pydantic",
    "ignore:Deprecated call to `pkg_resources\\.declare_namespace\\('.*'\\):DeprecationWarning",
    "ignore::DeprecationWarning:google.rpc",
    "ignore:Format strings passed to MaskedConstant are ignored:FutureWarning:seaborn",
    "ignore:np.find_common_type is deprecated:DeprecationWarning", # TODO: Remove this once we migrate to pandas v2
]
# asyncio_mode="strict"
❯ DOTENV=.env.test SECRETS_DIR=../.secrets poetry run pytest api/service/report_test.py  -k test_create_images_with_missing -p no:celery -p no:xdist -p no:asyncio -p no:doubles -p no:cov -p no:anyio -p no:faker -p no:hypothesispytest -p no:subtests -p no:xdist -p no:schemathesis
======================================== test session starts =========================================
platform linux -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /home/tom/Documents/dev/octopize/avatar/platform/api
configfile: pyproject.toml
plugins: mock-3.11.1
collected 23 items / 22 deselected / 1 selected                                                      

api/service/report_test.py .                                                                   [100%]

================================== 1 passed, 22 deselected in 1.93s ==================================

Output of pip list

Package                       Version
----------------------------- --------------------
aiodns                        3.0.0
aiohttp                       3.8.3
aiomultiprocess               0.9.0
aiosignal                     1.2.0
alabaster                     0.7.12
anyio                         3.6.2
appdirs                       1.4.3
apturl                        0.5.2
argcomplete                   2.0.0
argopt                        0.8.2
asttokens                     2.0.5
async-timeout                 4.0.2
attrs                         18.2.0
Babel                         2.9.1
backcall                      0.2.0
bc-detect-secrets             1.3.9
bc-python-hcl2                0.3.47
bcrypt                        3.1.7
beautifulsoup4                4.10.0
black                         22.1.0
blinker                       1.4
boto3                         1.24.93
botocore                      1.27.93
breathe                       4.32.0
Brlapi                        0.7.0
bump-pydantic                 0.6.1
bump-testclient               0.3.0
cached-property               1.5.1
cachetools                    5.2.0
certifi                       2019.11.28
cffi                          1.15.1
cfgv                          3.3.1
chardet                       3.0.4
charset-normalizer            2.1.1
chrome-gnome-shell            0.0.0
cli-helpers                   2.3.0
click                         8.0.3
click-option-group            0.5.5
cloudpickle                   2.2.1
cloudsplaining                0.5.0
colorama                      0.4.4
command-not-found             0.3
ConfigArgParse                1.5.3
configobj                     5.0.6
contextlib2                   21.6.0
cryptography                  2.8
cssselect                     1.1.0
ctop                          1.0.0
cupshelpers                   1.0
cycler                        0.11.0
cyclonedx-python-lib          3.1.0
dask                          2023.1.1
dbus-python                   1.2.16
decorator                     5.1.1
deep-merge                    0.0.4
defer                         1.0.6
distlib                       0.3.4
distro                        1.4.0
distro-info                   0.23+ubuntu1.1
dnspython                     2.4.1
docker                        4.1.0
docker-compose                1.25.0
dockerfile-parse              1.2.0
dockerpty                     0.4.1
docopt                        0.6.2
docutils                      0.17.1
dpath                         1.5.0
duplicity                     0.8.12.0
email-validator               2.0.0.post2
entrypoints                   0.3
executing                     0.8.2
Faker                         19.2.0
fasteners                     0.14.1
filelock                      3.4.2
fonttools                     4.29.1
frozenlist                    1.3.1
fsspec                        2023.1.0
future                        0.18.2
git-fame                      2.0.1
gitdb                         4.0.9
GitPython                     3.1.29
graphviz                      0.19.1
h11                           0.14.0
html5lib                      1.0.1
httpcore                      0.16.2
httplib2                      0.14.0
httpx                         0.23.1
hunter                        3.6.1
identify                      2.4.1
idna                          2.8
imagesize                     1.3.0
importlib-metadata            1.5.0
importlib-resources           5.10.0
ipython                       8.0.1
jedi                          0.18.1
Jinja2                        3.0.3
jmespath                      1.0.1
jsonpath-ng                   1.5.3
jsonschema                    3.2.0
junit-xml                     1.9
jupyter-client                7.0.6
jupyter-core                  4.9.2
keyring                       18.0.1
kiwisolver                    1.3.2
language-selector             0.1
lark                          1.1.3
launchpadlib                  1.10.13
lazr.restfulclient            0.14.2
lazr.uri                      1.0.3
libcst                        0.4.9
locket                        1.0.0
lockfile                      0.12.2
louis                         3.12.0
lxml                          4.5.0
macaroonbakery                1.3.1
Mako                          1.1.0
manhole                       1.8.0
Markdown                      3.4.1
markdown-it-py                3.0.0
MarkupSafe                    2.0.1
matplotlib-inline             0.1.3
mdurl                         0.1.2
meld                          3.20.2
monotonic                     1.5
more-itertools                4.2.0
multidict                     6.0.2
mypy-extensions               0.4.3
nest-asyncio                  1.5.4
netifaces                     0.10.4
networkx                      2.6.3
nodeenv                       1.6.0
numpy                         1.17.4
numpydoc                      1.2
oauthlib                      3.1.0
olefile                       0.46
packageurl-python             0.10.4
packaging                     21.3
paramiko                      2.6.0
parso                         0.8.3
partd                         1.3.0
pathspec                      0.9.0
pdflatex                      0.1.3
pexpect                       4.6.0
pickleshare                   0.7.5
Pillow                        7.0.0
pip                           23.2.1
pip-licenses                  3.5.4
pipx                          1.0.0
platformdirs                  2.4.1
ply                           3.11
policy-sentry                 0.12.4
policyuniverse                1.5.0.20220613
pre-commit                    3.3.3
prettytable                   3.4.1
prompt-toolkit                3.0.28
protobuf                      3.6.1
psutil                        5.5.1
PTable                        0.9.2
pure-eval                     0.2.2
pyan3                         1.2.1
pyathena                      2.23.0
pycairo                       1.16.2
pycares                       4.2.2
pycep-parser                  0.3.9
pycparser                     2.21
pycups                        1.9.73
pydata-sphinx-theme           0.7.2
pydeps                        1.10.18
Pygments                      2.15.1
PyGObject                     3.36.0
PyJWT                         1.7.1
pymacaroons                   0.13.0
PyNaCl                        1.3.0
pyparsing                     3.0.6
pyRFC3339                     1.1
pyrsistent                    0.15.5
pyston                        2.3.5
pyston-autoload               2.3.5
python-apt                    2.0.1+ubuntu0.20.4.1
python-dateutil               2.7.3
python-debian                 0.1.36+ubuntu1.1
pytz                          2021.3
pyxdg                         0.26
PyYAML                        6.0
pyzmq                         22.3.0
railroad-diagrams             1.1.1
regex                         2022.9.13
reportlab                     3.5.34
requests                      2.22.0
requests-unixsocket           0.2.0
rfc3986                       1.5.0
rich                          13.4.2
s3transfer                    0.6.0
schema                        0.7.5
scour                         0.37
SecretStorage                 2.3.1
semantic-version              2.10.0
setproctitle                  1.3.2
setuptools                    65.5.0
simplejson                    3.16.0
six                           1.14.0
smmap                         5.0.0
sniffio                       1.3.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.3.1
Sphinx                        4.2.0
sphinx-panels                 0.6.0
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
sqlparse                      0.4.3
stack-data                    0.1.4
stdlib-list                   0.8.0
systemd-python                234
tabulate                      0.9.0
tenacity                      8.2.2
termcolor                     2.0.1
texttable                     1.6.2
toml                          0.10.2
tomli                         2.0.1
toolz                         0.12.0
tornado                       6.1
tqdm                          4.66.1
traitlets                     5.1.1
typer                         0.7.0
typing_extensions             4.4.0
typing-inspect                0.8.0
ubuntu-advantage-tools        8001
ubuntu-drivers-common         0.0.0
ufw                           0.36
unattended-upgrades           0.1
update-checker                0.18.0
urllib3                       1.25.8
usb-creator                   0.3.7
userpath                      1.8.0
virtualenv                    20.13.0
wadllib                       1.3.3
wcwidth                       0.2.5
webencodings                  0.5.1
websocket-client              0.53.0
wheel                         0.34.2
xkit                          0.0.0
yarl                          1.8.1
zipp                          3.9.0
❯ uname -a
Linux tom-ThinkPad-X1-Carbon-Gen-9 5.15.0-84-generic #93~20.04.1-Ubuntu SMP Wed Sep 6 16:15:40 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
The-Compiler commented 11 months ago

Do you have something along the lines of a bare except: or except Exception: around the code raising the warning perhaps?

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] commented 10 months ago

This issue was closed because it has been inactive for 7 days since being marked as stale.