Created
March 10, 2025 13:50
-
-
Save tlandschoff-scale/d20fe4a6dc7a4b595dcd42562be9fd20 to your computer and use it in GitHub Desktop.
Illustrate failure to configure warnings in pytest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDeprecationWarning(DeprecationWarning): | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import warnings | |
from app import MyDeprecationWarning | |
def pytest_configure(): | |
# Configure app specific warning as error. | |
warnings.filterwarnings("error", category=MyDeprecationWarning) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ghcr.io/astral-sh/uv:python3.13-bookworm | |
RUN uv python install 3.7 3.13 | |
RUN mkdir /demo | |
WORKDIR /demo | |
ADD app.py conftest.py test_depwarn.py /demo/ | |
RUN uv init --python 3.7 && uv add 'pytest>3,<3.1' | |
RUN uv run pytest | |
RUN uv python pin 3.13 && uv add 'pytest>7' | |
RUN uv run pytest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import warnings | |
import pytest | |
from app import MyDeprecationWarning | |
def test_deprecated(): | |
with pytest.raises(MyDeprecationWarning): | |
warnings.warn("Stuff deprecated", category=MyDeprecationWarning) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment