-
-
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
Refactor src/_pytest/config/__init__.py to use the warnings module instead of stderr for warnings #7396
Conversation
Hey @nicoddemus @RonnyPfannschmidt - any idea why codecov says I only hit 66% of the diff? I ( think I ) have adequate testing |
based on the coverage diff view i would guess that the assertion disabled case was not hit by coverage, which it should be if i remember correct as such i believe a investigation is needed into that, |
unfortunately i wont be able to do any deep work on pytest until the next weekend |
Do we want to allow this to merge before that? Or should we hold off until we check codecov |
I'll defer to @nicoddemus on that one |
This definitely looks like an issue with codecov, and not the PR. I updated this PR with 33de350 to parametrize some of the tests, and it looks like that dropped coverage from 66% to 60% even though no coverage was added or taken away. I suggest we open an issue to track this and treat it separately @nicoddemus and @RonnyPfannschmidt |
@nicoddemus are you opposed to merging this in and treating the codecov as a separate issue? |
Gentle ping @nicoddemus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup! I left a few minor comments/questions.
As a follow up I think it would be good to move _issue_warning_captured
from _pytest.warning
to some more suitable place, probably _pytest.config
, since it's obviously misplaced now - every single caller of it imports it lazily due to import cycles...
src/_pytest/config/__init__.py
Outdated
from _pytest.warnings import _issue_warning_captured | ||
|
||
_issue_warning_captured( | ||
PytestConfigWarning(message), self.hook, stacklevel=2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always not 100% which value it should be, so just making sure, did you check the stacklevel=2
is the best value here? I think it would be best to point at the caller of _warn_or_fail_if_strict
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the caller of _validate_keys
is _preparse
, which already had stacklevel=2
, so we'd want 2 here as well right @bluetech ?
src/_pytest/config/__init__.py
Outdated
" using python -O?" | ||
) | ||
_issue_warning_captured( | ||
PytestConfigWarning(warning_text), self.hook, stacklevel=2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here re. stacklevel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same reply as to your original question. That would mean we want stacklevel 2 here as well right?
BTW when I checked it out there was a minor conflict with |
Definitely agree, every caller also has access to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @gnikonorov thanks!
Please take a look at the comments made by @bluetech, I think they are worth doing/checking.
We should follow up with making _issue_warning_captured
a method of Config
after this gets merged.
@bluetech - I looked at the diff and I don't see any changes/conflicts, and just merged in upstream. What do you see is inconsistent? |
I guess it was just local, github didn't complain as well. Anyway it's good now, thanks! (BTW, I personally prefer rebasing PRs instead of merging master into them, I find that a little cleaner, but whatever you prefer is OK).
I'm not sure I understand, so let me explain more what I mean. The
the question is whatever 0:
1:
2: See above. 3:
4:
5:
etc... In this case IMO the best one is |
Merged myself to override the patch coverage issue |
Closes #7295
Refactors
src/_pytest/config/__init__.py
to use thewarnings
module instead of writing out warnings tostderr