-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Duplicate file collection for non-pattern matching file #2679
Comments
@elliterate thanks for the report and the well detailed reproducer, we appreciate it. 👍 |
This seems to be 'work as designed'. The code in the module if not parent.session.isinitpath(path):
# do this check ONLY if path NOT IN initial paths
for pat in parent.config.getini('python_files'):
if path.fnmatch(pat):
break
else:
return
# the path is considered collected if the code reaches this point So what happened in the example of @elliterate is the file So I guess there're some options:
I'm in for option 1. PS: @nicoddemus sorry for deleting my previous comment. I didn't understand the issue well enough. |
I don't understand how you reached that conclusion. Yes, this is what the code does, but that doesn't mean its behavior is by design. (If that were true, then there would be no such thing as a bug in software; everything would by definition be a feature, since that is how the code works.) In #1187, the argument was made that if In this case, however, while |
This is why I think it should be clarified in the doc. I think you understand When a user specifies a file, my understanding is it's not only to run just a file among many files but also to run a file whose name may not match the default patterns. So naming it We certainly could make pytest ignore a file that doesn't match the pattern despite being specified explicitly by a user. I just think that some users may have use the tool like this and changing this would resulting in another user reporting another issue. It's not on me to decide on which way the development of pytest should follow. I was looking at this issue and wanted to understand what happened and gain and better understanding of the codebase. I'm happy with whatever options the core developers want for this issue. |
Btw, I'm with you on this. I'm not a fan of having a file collected twice, but it was settled in another argument. And in case you haven't noticed, I have worked as designed in quote. For me this issue seems to be a combination of having a file collected twice and having an explicitly specified test file skipped the file name patterns. |
When
py.test
is executed withfile_or_dir
arguments for:test_*.py
),the file will be collected twice.
I believe this is because the file in question is considered for collection twice (once as a member of an explicitly-requested directory and again as an explicitly-requested file) and matches
Session#isinitpath
both times, thus being collected twice.This is similar to #1187, except that the file would not ordinarily be collected as a member of the directory, since it does not match the Python test module pattern. As such, this is not a case of explicitly requesting collection of the same
file_or_dir
twice.Example
Setup
Scenario A: Default test collection
Scenario B: Explicit directory test collection
Scenario C: Explicit non-matching file test collection
Scenario D: Explicit directory and non-matching file test collection
The text was updated successfully, but these errors were encountered: