Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config option filterwarnings ignore::DeprecationWarning does not supress warnings #13145

Closed
MarkusBiggus opened this issue Jan 19, 2025 · 15 comments
Assignees

Comments

@MarkusBiggus
Copy link

Follow on from issue: config option filterwarnings ignore::DeprecationWarning:* crashes

Given the discussion, I should have mentioned the motivation for adding asterisk was because it didn't work without the asterisk. This is the real issue.

With Python3.12 when I tried to supress DeprecationWarning, I first used correct syntax:

[pytest]
minversion = 8.0
asyncio_mode = auto
asyncio_default_fixture_loop_scope = function
filterwarnings = ignore::DeprecationWarning

Which still shows deprecation warnings with Python3.13 too:

pytest tests/test_config_flow.py  -k test_options_flow_works
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/josepy/util.py:26: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def __init__(self, wrapped: Union[crypto.X509, crypto.X509Req]) -> None:
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/acme/crypto_util.py:280: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def _pyopenssl_cert_or_req_all_names(loaded_cert_or_req: Union[crypto.X509, crypto.X509Req]
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/acme/crypto_util.py:291: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def _pyopenssl_cert_or_req_san(cert_or_req: Union[crypto.X509, crypto.X509Req]) -> List[str]:
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/acme/crypto_util.py:318: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def _pyopenssl_cert_or_req_san_ip(cert_or_req: Union[crypto.X509, crypto.X509Req]) -> List[str]:
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/acme/crypto_util.py:338: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def _pyopenssl_extract_san_list_raw(cert_or_req: Union[crypto.X509, crypto.X509Req]) -> List[str]:
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/acme/crypto_util.py:372: DeprecationWarning: X509Extension support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  extensions: Optional[List[crypto.X509Extension]] = None,
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/homeassistant/components/http/__init__.py:310: DeprecationWarning: Inheritance class HomeAssistantApplication from web.Application is discouraged
  class HomeAssistantApplication(web.Application):
Test session starts (platform: linux, Python 3.13.0, pytest 8.3.4, pytest-sugar 1.0.0)
rootdir: /home/homeassistant/sonnenbackup
configfile: pytest.ini
plugins: unordered-0.6.1, aiohttp-1.0.5, syrupy-4.8.0, xdist-3.6.1, asyncio-0.25.2, socket-0.7.0, mock-3.14.0, picked-0.5.0, cov-6.0.0, pytest_freezer-0.4.8, anyio-4.8.0, homeassistant-custom-component-0.13.201, timeout-2.3.1, respx-0.21.1, requests-mock-1.12.1, sugar-1.0.0, github-actions-annotate-failures-0.2.0
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function
collected 9 items / 8 deselected / 1 selected

I'd forgotten about it until Python3.13 crashed pytest.

pip list


Package                                 Version
--------------------------------------- -----------
acme                                    3.0.1
aiodns                                  3.2.0
aiohappyeyeballs                        2.4.4
aiohasupervisor                         0.2.2b5
aiohttp                                 3.11.11
aiohttp-cors                            0.7.0
aiohttp-fast-zlib                       0.2.0
aiooui                                  0.1.7
aiosignal                               1.3.2
aiozoneinfo                             0.2.1
annotated-types                         0.7.0
anyio                                   4.8.0
astral                                  2.2
async_interrupt                         1.2.0
async-timeout                           5.0.1
asyncio                                 3.4.3
asyncmock                               0.4.2
atomicwrites-homeassistant              1.4.1
attrs                                   24.2.0
audioop-lts                             0.2.1
awesomeversion                          24.6.0
bcrypt                                  4.2.0
bleak                                   0.22.3
bleak-retry-connector                   3.6.0
bluetooth-adapters                      0.20.2
bluetooth-auto-recovery                 1.4.2
bluetooth-data-tools                    1.20.0
boolean.py                              4.0
boto3                                   1.35.94
botocore                                1.35.94
btsocket                                0.3.0
certifi                                 2024.12.14
cffi                                    1.17.1
charset-normalizer                      3.4.1
ciso8601                                2.3.2
coverage                                7.6.8
cronsim                                 2.6
cryptography                            44.0.0
dbus-fast                               2.28.0
envs                                    1.4
execnet                                 2.1.1
fnv-hash-fast                           1.0.2
fnvhash                                 0.1.0
freezegun                               1.5.1
frozenlist                              1.5.0
h11                                     0.14.0
habluetooth                             3.7.0
hass-nabucasa                           0.87.0
home-assistant-bluetooth                1.13.0
homeassistant                           2025.1.0
httpcore                                1.0.7
httpx                                   0.27.2
idna                                    3.10
ifaddr                                  0.2.0
iniconfig                               2.0.0
isal                                    1.7.1
Jinja2                                  3.1.5
jmespath                                1.0.1
josepy                                  1.14.0
license-expression                      30.4.0
load-dotenv                             0.1.0
lru-dict                                1.3.0
MarkupSafe                              3.0.2
mashumaro                               3.15
mock                                    5.1.0
mock-open                               1.4.0
multidict                               6.1.0
numpy                                   2.2.0
orjson                                  3.10.12
packaging                               24.2
paho-mqtt                               1.6.1
pillow                                  11.0.0
pip                                     24.3.1
pipdeptree                              2.23.4
pluggy                                  1.5.0
propcache                               0.2.1
psutil                                  6.1.1
psutil-home-assistant                   0.0.1
pycares                                 4.5.0
pycognito                               2024.5.1
pycparser                               2.22
pydantic                                2.10.4
pydantic_core                           2.27.2
PyJWT                                   2.10.1
pylint-per-file-ignores                 1.3.2
pyOpenSSL                               24.3.0
pyRFC3339                               2.0.1
PyRIC                                   0.1.6.3
pytest                                  8.3.4
pytest-aiohttp                          1.0.5
pytest-asyncio                          0.25.2
pytest-cov                              6.0.0
pytest_freezer                          0.4.8
pytest-github-actions-annotate-failures 0.2.0
pytest-homeassistant-custom-component   0.13.201
pytest-mock                             3.14.0
pytest-picked                           0.5.0
pytest-socket                           0.7.0
pytest-sugar                            1.0.0
pytest-timeout                          2.3.1
pytest-unordered                        0.6.1
pytest-xdist                            3.6.1
python-dateutil                         2.9.0.post0
python-dotenv                           1.0.1
python-slugify                          8.0.4
pytz                                    2024.2
PyYAML                                  6.0.2
requests                                2.32.3
requests-mock                           1.12.1
responses                               0.25.3
respx                                   0.21.1
s3transfer                              0.10.4
securetar                               2024.11.0
setuptools                              75.7.0
six                                     1.17.0
sniffio                                 1.3.1
snitun                                  0.39.1
sonnen_api_v2                           0.5.13
SQLAlchemy                              2.0.36
standard-aifc                           3.13.0
standard-chunk                          3.13.0
standard-telnetlib                      3.13.0
syrupy                                  4.8.0
termcolor                               2.5.0
text-unidecode                          1.3
tqdm                                    4.66.5
typing_extensions                       4.12.2
tzdata                                  2024.2
tzlocal                                 5.2
uart-devices                            0.1.0
ulid-transform                          1.0.2
urllib3                                 1.26.20
urllib3-mock                            0.3.3
usb-devices                             0.4.5
uv                                      0.5.8
voluptuous                              0.15.2
voluptuous-openapi                      0.0.5
voluptuous-serialize                    2.6.0
webrtc-models                           0.3.0
yarl                                    1.18.3

O/S: Ubuntu 24.04.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)

pytest: Platform: linux, Python 3.13.0, pytest 8.3.4, pytest-sugar 1.0.0

@webknjaz
Copy link
Member

Looks like those modules are loaded before pytest's settings are processed. You should be able to use python -W to capture them.

@MarkusBiggus
Copy link
Author

Thanks for the advice, but I'm bit too novice to follow it.

Found this in help:
python3 -W action:message:category:module:lineno

Tried this command which has not suppressed messages. Really not sure I got the command right.

python3 -W ignore:"CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.":DeprecationWarning:"josepy/util":26
Python 3.13.0 (main, Jan  8 2025, 09:05:47) [GCC 13.3.0] on linux

pytest tests/test_config_flow.py  -k test_options_flow_works

/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/josepy/util.py:26: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def __init__(self, wrapped: Union[crypto.X509, crypto.X509Req]) -> None:

Tried a few variations on the module name with varying 'invalid module name' errors.

Seems to be quite different command format to the Stack Overflow articles I found on supressing warnings.

Any idea what it expects as the 'module' parameter?

@The-Compiler
Copy link
Member

It should probably be josepy.util, but just like with filterwarnings, you can leave parts empty or off completely at the end.

@graingert
Copy link
Member

graingert commented Jan 21, 2025

is this fixed in main, I changed when filters are applied/removed?

@graingert
Copy link
Member

graingert commented Jan 21, 2025

@MarkusBiggus what package is this? Is it https://github.com/home-assistant/core/ ? could you link to a failing CI build?

@graingert graingert self-assigned this Jan 21, 2025
@webknjaz
Copy link
Member

webknjaz commented Jan 22, 2025

Tried this command which has not suppressed messages. Really not sure I got the command right.

@MarkusBiggus from your log it seems like you're executing a separate Python process with the warning setting and then additionally attempt to execute pytest.

That should be in the same command. As in python3 -Wignore::DeprecationWarning -Im pytest.


Relevant interpreter docs:

@MarkusBiggus
Copy link
Author

Thanks, that command did supress the warnings.
Nice clean output with working tests.

python3 -Wignore::DeprecationWarning -Im pytest
Test session starts (platform: linux, Python 3.13.0, pytest 8.3.4, pytest-sugar 1.0.0)
rootdir: /home/homeassistant/sonnenbackup
configfile: pytest.ini
plugins: unordered-0.6.1, aiohttp-1.0.5, syrupy-4.8.0, xdist-3.6.1, asyncio-0.25.2, socket-0.7.0, mock-3.14.0, picked-0.5.0, cov-6.0.0, pytest_freezer-0.4.8, anyio-4.8.0, homeassistant-custom-component-0.13.201, timeout-2.3.1, respx-0.21.1, requests-mock-1.12.1, sugar-1.0.0, github-actions-annotate-failures-0.2.0
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function
collected 11 items

 tests/test_batterieresponse.py ✓                                                                          9% ▉
 tests/test_config_flow.py ✓✓✓✓✓✓✓✓✓                                                                      91% █████████▏
 tests/test_options_flow.py ✓                                                                            100% ██████████

---------- coverage: platform linux, python 3.13.0-final-0 -----------
Coverage HTML written to dir tests/coverage


Results (3.74s):
      11 passed

@graingert
Copy link
Member

graingert commented Jan 22, 2025

But it should work without having to pass it to python -w did you try with pytest from the main branch?

@MarkusBiggus
Copy link
Author

Do you mean this way?
Didn't work, if so.

pytest tests -Wignore::DeprecationWarning
/home/homeassistant/sonnenbackup/.venv/lib/python3.13/site-packages/josepy/util.py:26: DeprecationWarning: CSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.
  def __init__(self, wrapped: Union[crypto.X509, crypto.X509Req]) -> None:

@graingert
Copy link
Member

This is with 8.4?

@MarkusBiggus
Copy link
Author

pytest 8.3.4

@graingert
Copy link
Member

Ah can you try it with the unreleased 8.4 on main?

@MarkusBiggus
Copy link
Author

Just had a quick look at main and saw no sign of 8.4.

I've mastered the basics of github and not much else.
I think that request is beyond my skillset at the moment.

@graingert
Copy link
Member

here's a demo installing from git, showing the unreleased 8.4:

✘  graingert@conscientious  SonnenBackup  ~/projects/SonnenBackup   main ± pip install git+https://github.com/pytest-dev/pytest.git
Collecting git+https://github.com/pytest-dev/pytest.git
  Cloning https://github.com/pytest-dev/pytest.git to /tmp/pip-req-build-mpdeqts5
  Running command git clone --filter=blob:none --quiet https://github.com/pytest-dev/pytest.git /tmp/pip-req-build-mpdeqts5
  Resolved https://github.com/pytest-dev/pytest.git to commit 2f1c143b17edab8e1525d553e0757a5fc27bb068
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: iniconfig in /home/graingert/.virtualenvs/SonnenBackup/lib/python3.13/site-packages (from pytest==8.4.0.dev329+g2f1c143b1) (2.0.0)
Requirement already satisfied: packaging in /home/graingert/.virtualenvs/SonnenBackup/lib/python3.13/site-packages (from pytest==8.4.0.dev329+g2f1c143b1) (24.2)
Requirement already satisfied: pluggy<2,>=1.5 in /home/graingert/.virtualenvs/SonnenBackup/lib/python3.13/site-packages (from pytest==8.4.0.dev329+g2f1c143b1) (1.5.0)
Building wheels for collected packages: pytest
  Building wheel for pytest (pyproject.toml) ... done
  Created wheel for pytest: filename=pytest-8.4.0.dev329+g2f1c143b1-py3-none-any.whl size=347347 sha256=c59fbe2568b67c871c2705437112f3140c8130f1636a15be33df077c7beac044
  Stored in directory: /tmp/pip-ephem-wheel-cache-6l45ddpe/wheels/e1/d2/a8/19b4799a4937007ca553df4ad12841eb987ffb430ad5e2ff68
Successfully built pytest
Installing collected packages: pytest
  Attempting uninstall: pytest
    Found existing installation: pytest 8.3.4
    Uninstalling pytest-8.3.4:
      Successfully uninstalled pytest-8.3.4
Successfully installed pytest-8.4.0.dev329+g2f1c143b1
 graingert@conscientious  SonnenBackup  ~/projects/SonnenBackup   main ± pytest
ImportError while loading conftest '/home/graingert/projects/SonnenBackup/tests/conftest.py'.
tests/conftest.py:8: in <module>
    from pytest_homeassistant_custom_component.common import MockConfigEntry
E   ModuleNotFoundError: No module named 'pytest_homeassistant_custom_component'

I'm running against https://github.com/MarkusBiggus/SonnenBackup/tree/8611f7d635219596fb4d473d089a4135ba26d266 but the tests won't run at all

please advise how to run your suite, or try to run with pytest 8.4 in your configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants