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

Support negative patterns in python_files option. #13111

Open
ktbarrett opened this issue Jan 6, 2025 · 3 comments
Open

Support negative patterns in python_files option. #13111

ktbarrett opened this issue Jan 6, 2025 · 3 comments
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity

Comments

@ktbarrett
Copy link

What's the problem this feature will solve?

This feature will allow users to create exceptions to python files to look for tests or magic like assertion rewriting is applied to.

Describe the solution you'd like

Being able to specify negative patterns in the python_files option such as !my/**/pattern/*.py or similar.

Alternative Solutions

???

Additional context

Would allow workarounds to #10845, scipy/scipy#22236, and cocotb/cocotb#4343.

@The-Compiler
Copy link
Member

There is already an ignore option and the norecursedirs setting. For the scenario where python_files works as intended (selecting which modules in the current directory should be picked up as tests), I don't think pytest needs yet another way to do the same thing.

However, I'm surprised that setting python_files = *.py causes pytest to apply assertion rewriting to all Python files, even outside the current directory. That feels like a bug to me, I'll comment in #10845 about that part.

@ktbarrett
Copy link
Author

I'm guessing ignore takes precedence over (applied after) python_files? That should work.

A meta-comment... I've seen several projects make this same mistake of separating inclusions and exclusions into two different variables rather than using one, supporting negative patterns, and having a series of patterns apply in order. IIRC I remember myself being a part of this same issue on coverage. It always ends up becoming a sore point and maintenance effort.

However, I'm surprised that setting python_files = *.py causes pytest to apply assertion rewriting to all Python files, even outside the current directory.

That's desired behavior.

@The-Compiler
Copy link
Member

I'm guessing ignore takes precedence over (applied after) python_files? That should work.

I believe the assertion rewriting doesn't take ignore into account at all.

That's desired behavior.

Can you elaborate? I don't think it is, as it's both undocumented and surprising.

@The-Compiler The-Compiler added the status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs information reporter needs to provide more information; can be closed after 2 or more weeks of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants