Introduction
We use pytest.warns to check if our code shows the right warnings. This helps catch small problems early.
When you want to make sure a function warns about deprecated features.
When you expect a warning for unsafe or unusual code use.
When testing that a warning message appears during a specific action.
When you want to confirm your code warns users about upcoming changes.
When you want to catch warnings as part of automated tests.