-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Take the FORCE_COLOR
and NO_COLOR
environment variables into account
#9128
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Any ideas of how to detect that a reporter is attached to |
FORCE_COLOR
and NO_COLOR
environnement variables into accountFORCE_COLOR
and NO_COLOR
environement variables into account
FORCE_COLOR
and NO_COLOR
environement variables into accountFORCE_COLOR
and NO_COLOR
environment variables into account
This comment has been minimized.
This comment has been minimized.
+1 to I suggest to leave https://docs.pytest.org/en/stable/reference/reference.html#envvar-PY_COLORS |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Stavros Ntentos <[email protected]>
Use the `_is_env_set_and_non_empty`, and the logic decided in the issue, to modify the reporter(s) list accordingly. At most, one reporter should be modified - the one going to `stdout`. Hooking before the `self.set_reporter` was deemed as the smallest incision. For no particular reason, it was decided that `_handle_force_color_no_color` would modify its input; so there would be no need for re-assigning the input we want to modify anyway. Signed-off-by: Stavros Ntentos <[email protected]>
Signed-off-by: Stavros Ntentos <[email protected]>
Signed-off-by: Stavros Ntentos <[email protected]>
51950fe
to
4427cf3
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9128 +/- ##
=======================================
Coverage 95.83% 95.84%
=======================================
Files 174 174
Lines 18995 19030 +35
=======================================
+ Hits 18204 18239 +35
Misses 791 791
|
https://results.pre-commit.ci/run/github/47671127/1736488806.KxdAH7XbRZuDggnznvulyQ
If the suggestion is followed, I get: $ pre-commit run -a
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
ruff.....................................................................Passed
ruff-doc.................................................................Passed
copyright-notice.........................................................Passed
isort....................................................................Passed
black....................................................................Passed
black-doc................................................................Passed
black-disable-checker....................................................Passed
pylint...................................................................Failed
- hook id: pylint
- exit code: 1
Executable `pylint` not found
Check newsfragments......................................................Passed
rstcheck.................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
pylint/lint/pylinter.py:307: error: "Sequence[BaseReporter]" has no attribute "pop" [attr-defined]
pylint/lint/pylinter.py:308: error: "Sequence[BaseReporter]" has no attribute "append" [attr-defined]
pylint/lint/pylinter.py:322: error: "Sequence[BaseReporter]" has no attribute "pop" [attr-defined]
pylint/lint/pylinter.py:323: error: "Sequence[BaseReporter]" has no attribute "append" [attr-defined]
Found 4 errors in 1 file (checked 278 source files)
prettier.................................................................Passed
pydocstringformatter.....................................................Passed
Check package with Pyroma................................................Passed
bandit...................................................................Passed
codespell................................................................Passed I'm all ears for mypy/code improvement 🙌 |
This comment has been minimized.
This comment has been minimized.
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.
Left some comments that were a bit hard to explain as in line comments, hope you don't mind.
This LGTM expect for the small change in the news entry and the test
[True, False], | ||
ids=lambda force_color: f"{force_color=}", | ||
) | ||
def test_handle_force_color_no_color( |
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'd like to have @Pierre-Sassoulas's opinion on this test. This isn't really the pattern we would normally use (e.g., use of pytest_generate_tests
) but I'm not sure how he would prefer this to be tested.
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 was a bit too quick to "ask for help", since Windows tests fail (https://github.com/pylint-dev/pylint/actions/runs/12734784829/job/35492756662?pr=9128)
I was aiming very specifically at #9128 (comment) (which you kindly fix-up-ed yourself ❤️)
At least nowadays I have "somewhat" of Python setup in Windows and I could try to decipher this error.
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'd like to have @Pierre-Sassoulas's opinion on this test. This isn't really the pattern we would normally use (e.g., use of
pytest_generate_tests
) but I'm not sure how he would prefer this to be tested.
But for the comment at-hand:
@pytest.mark.parametrize(
"no_color",
[True, False],
ids=lambda no_color: f"{no_color=}",
)
is trivial to test like so. For attaching reporters, not so much.
I could ... try to run this code once, and @pytest.mark.parametrize
with the output of the code (ie parameters
) instead
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 feel like the test is as (or more) complicated than the code we want to test, which is bad. A middle ground would be to parametrize only one parameter and hardcode the other one ? Something like:
@pytest.mark.parametrize(
"force_color,expected",
[(True, False)],
ids=lambda force_color: f"{force_color=}",
)
def test_handle_force_color_no_color_true_text_reporter(...)
monkeypatch.setenv(NO_COLOR, "1")
reporter = TextReporter
@pytest.mark.parametrize(
"force_color",
[True, False],
ids=lambda force_color: f"{force_color=}",
)
def test_handle_force_color_no_color_colorized_text_reporter(...)
monkeypatch.setenv(NO_COLOR, "")
reporter = ColorizedTextReporter
@pytest.mark.parametrize(
"force_color,expected",
[(True, False)],
ids=lambda force_color: f"{force_color=}",
)
def test_handle_force_color_no_color_true_text_reporter(...)
monkeypatch.setenv(NO_COLOR, "1")
reporter = TextReporter
@pytest.mark.parametrize(
"force_color",
[True, False],
ids=lambda force_color: f"{force_color=}",
)
def test_handle_force_color_no_color_colorized_text_reporter(...)
monkeypatch.setenv(NO_COLOR, "")
reporter = ColorizedTextReporter
I'm not sure if it's better than what Daniel suggest. Especially if we choose the parameter badly (we should parametrize the one that doesn't change anything because the other take precedance). Also it seems we don't actually test the color output but a warning instead?
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.
Yes, I agree with Pierre that it would probably be better to bit more explicit and write out more of the code itself.
This comment has been minimized.
This comment has been minimized.
OTOH, @DanielNoord pls note that the latest changes you committed also makes pypy tests fail? Originally (https://github.com/pylint-dev/pylint/actions/runs/12704163354) they didn't (Note to me: Historical runs: https://github.com/pylint-dev/pylint/actions/workflows/tests.yaml?query=branch%3Aimpr%2F3995%2FNO_COLOR%2BFORCE_COLOR) |
Yeah, I wanted to spend time to fix the tests as well but would first like the opinion of Pierre about the current "design" of them. I would probably prefer to not use "fancy" parameterisation for these tests, but instead write them out individually. In the long run I think that is better for maintainability. Before committing to this I would like the opinion of another maintainer though. |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Daniël van Noord <[email protected]>
This looks great, thank you for being persistent with this PR @stdedos ! |
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit cd55074 |
Support for
NO_COLOR
andFORCE_COLOR
(andPY_COLORS
, as an alias toFORCE_COLOR
)environment variables has been added. When running
pylint
, the reporter that reportsto
stdout
will be modified according to the requested mode.The order is:
NO_COLOR
FORCE_COLOR
,PY_COLORS
--output=...
.Signed-off-by: Stavros Ntentos [email protected]
skip-news
if the change does not need to be in the changelog.towncrier create <IssueNumber>.<type>
which will beincluded in the changelog.
<type>
can be one of the types defined in./towncrier.toml
.If necessary you can write details or offer examples on how the new change is supposed to work.
tox -e docs
Don't hesitate to open multiple PRs if the change requires it. If your review is so
big it requires to actually plan and allocate time to review, it's more likely
that it's going to go stale.
and preferred name in
script/.contributors_aliases.json
Type of Changes
Description
Fixes #3995