Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify docs on specifying multiple filters with pytest.mark.filterwarnings #12966

Open
soxofaan opened this issue Nov 15, 2024 · 2 comments
Open

Comments

@soxofaan
Copy link
Contributor

Specifying multiple filterwarnings filter in the correct order can be a bit confusing.

When using @pytest.mark.filterwarnings as decorator, one has to use the reverse order compared to stdlib's warnings.filterwarnings (because of the order that decorators are evaluated).
When using pytestmark (list of pytest.mark.filterwarnings marks), it's the other way around.

I think this deserves a bit of clarification in the docs

FYI: I'm actually already working on a PR for this

soxofaan added a commit to soxofaan/pytest that referenced this issue Nov 15, 2024
patchback bot pushed a commit that referenced this issue Nov 16, 2024
nicoddemus pushed a commit that referenced this issue Nov 16, 2024
…tiple marks (#12967) (#12969)

(cherry picked from commit 71a35d4)

Co-authored-by: Stefaan Lippens <soxofaan@users.noreply.github.com>
@The-Compiler
Copy link
Member

The-Compiler commented Nov 16, 2024

According to the code, it's also possible to pass multiple arguments/filters into one decorator/mark instead of having to have multiple of them:

for mark in item.iter_markers(name="filterwarnings"):
for arg in mark.args:
warnings.filterwarnings(*parse_warning_filter(arg, escape=False))

That seems like a much easier and more consistent way to get to the same result, though it looks like the docs don't do a great job at pointing that out either. @soxofaan would you perhaps be interested in opening another PR detailing that a bit more too?

@soxofaan
Copy link
Contributor Author

Ah that's interesting. I kind of tried something like that by passing a single string with comma-separated filters, following PYTHONWARNINGS, which didn't work.
Passing multiple arguments is indeed cleaner and probably less confusing that the multi-decorator approach.

I'll see if I find some time to do a follow-up PR

Glyphack pushed a commit to Glyphack/pytest that referenced this issue Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants