Improve assert mod not in mods error message #11795
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #9765, add a better error message than
assert mod not in mods
. This would have been super useful to figure out from the error message the difference fromconftestpath
andmod.__file__
. Hopefully the #11708 will be merged and this error is less likely to occur, but at least if a variation of the issue occurs again there will be a better error message.Here is the error on my reproducer https://github.com/lesteve/pytest-issue-9765-reproducer:
For now I keep an
AssertionError
but let me know if you think another kind of error is more appropriate.It does not seem that easy to add a test for this ...
Let me know if you think this is worth adding a changelog for this or not!
Depending on how #11708 goes, this may need to be tweaked since a discrepancy between
mod.__file__
andstr(contestpath)
is likely not how this problem will show up. It could even lead to red-herring, since it will be potentially fine thatmod.__file__
andstr(conftestpath)
are not the consistent and people may be misled by reading comments like #9765 (comment) ...