[Python] Ignoring warning emitted by libs in `venv` using `pytest`

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using pytest lib for testing and sometimes I get warnings emitted in code in libs imported (all are in /venv directory).

    I do not want to turn off warnings that are emitted in code I wrote, but warnings emitted in code of any 3rd party lib are of no use.

    How to turn off or hide all warnings that come from code in /venv?

    One specific example for my use case can be:

    ============================================ warnings summary ============================================
    test_auth.py: 3 warnings
    C:\Users\User\<my project>\security.py:33: DeprecationWarning: datetim
    e.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    expire = datetime.utcnow() + timedelta(days=settings.REFRESH_TOKEN_EXPIRE_DAYS)
    ===
    ^ this line is in code I wrote, warnings should be turned on.
    ===

    test_auth.py: 2 warnings
    C:\Users\User\<my project>\venv\Lib\site-packages\jose\jwt.py:311: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    now = timegm(datetime.utcnow().utctimetuple())
    ===
    ^ this line is somewhere in python-jwt lib in /venv, I dont want to see them at all.
    ===


    I checked these ( 1 2 3 ) Qs, and they either turn off all warnings completely or ignore specific warnings or types of warnings - either is useless in my use case.

    Continue reading...

Compartilhe esta Página