Skip to content

Instantly share code, notes, and snippets.

@tlandschoff-scale
Created March 10, 2025 13:50
Show Gist options
  • Save tlandschoff-scale/d20fe4a6dc7a4b595dcd42562be9fd20 to your computer and use it in GitHub Desktop.
Save tlandschoff-scale/d20fe4a6dc7a4b595dcd42562be9fd20 to your computer and use it in GitHub Desktop.
Illustrate failure to configure warnings in pytest
class MyDeprecationWarning(DeprecationWarning):
pass
import warnings
from app import MyDeprecationWarning
def pytest_configure():
# Configure app specific warning as error.
warnings.filterwarnings("error", category=MyDeprecationWarning)
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
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