Community question ยท 3 years ago

Question #388851

How to ignore specific warning using Pytest?

Pytest has @pytest.mark.filterwarnings

using:

@pytest.mark.filterwarnings("ignore::DeprecationWarning")

works like a charm but I don't want to ignore all DeprecationWarning I want to ignore a specific one:

warnings.warn("Please use new_module.", DeprecationWarning)

I tried to do:

@pytest.mark.filterwarnings("ignore::DeprecationWarning: Please use new_module.")

but this doesn't work. I can't find the proper syntax to filter a specific message.

how can this be done?

Community responses

0 answers

Add your answer

Share the reasoning, tradeoffs, and code that make your answer useful.