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

Fix 4227: Black does not print errors with --quiet --check #4236

Merged
merged 10 commits into from Mar 13, 2024
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -44,6 +44,7 @@

### Documentation

- Note what happens when --check is called with --quiet (#4236)
dankrzeminski32 marked this conversation as resolved.
Show resolved Hide resolved
<!-- Major changes to documentation and policies. Small docs changes
don't need a changelog entry. -->

Expand Down
2 changes: 2 additions & 0 deletions docs/usage_and_configuration/the_basics.md
Expand Up @@ -183,6 +183,8 @@ Don't write the files back, just return the status. _Black_ will exit with:
- code 1 if some files would be reformatted; or
- code 123 if there was an internal error

If used in combination with `--quiet` then only the exit code will be returned.

dankrzeminski32 marked this conversation as resolved.
Show resolved Hide resolved
```console
$ black test.py --check
All done! ✨ 🍰 ✨
Expand Down
25 changes: 15 additions & 10 deletions tests/test_black.py
Expand Up @@ -483,9 +483,11 @@ def _mocked_calls() -> bool:

return _mocked_calls

with patch("pathlib.Path.iterdir", return_value=target_contents), patch(
"pathlib.Path.resolve", return_value=target_abspath
), patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])):
with (
patch("pathlib.Path.iterdir", return_value=target_contents),
patch("pathlib.Path.resolve", return_value=target_abspath),
patch("pathlib.Path.is_dir", side_effect=mock_n_calls([True])),
):
# Note that the root folder (project_root) isn't the folder
# named "root" (aka working_directory)
report = MagicMock(verbose=True)
Expand Down Expand Up @@ -2132,8 +2134,9 @@ def test_cache_single_file_already_cached(self) -> None:
@event_loop()
def test_cache_multiple_files(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
"concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
with (
cache_dir() as workspace,
patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor),
):
one = (workspace / "one.py").resolve()
one.write_text("print('hello')", encoding="utf-8")
Expand All @@ -2155,9 +2158,10 @@ def test_no_cache_when_writeback_diff(self, color: bool) -> None:
with cache_dir() as workspace:
src = (workspace / "test.py").resolve()
src.write_text("print('hello')", encoding="utf-8")
with patch.object(black.Cache, "read") as read_cache, patch.object(
black.Cache, "write"
) as write_cache:
with (
patch.object(black.Cache, "read") as read_cache,
patch.object(black.Cache, "write") as write_cache,
):
cmd = [str(src), "--diff"]
if color:
cmd.append("--color")
Expand Down Expand Up @@ -2286,8 +2290,9 @@ def test_write_cache_creates_directory_if_needed(self) -> None:
@event_loop()
def test_failed_formatting_does_not_get_cached(self) -> None:
mode = DEFAULT_MODE
with cache_dir() as workspace, patch(
"concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor
with (
cache_dir() as workspace,
patch("concurrent.futures.ProcessPoolExecutor", new=ThreadPoolExecutor),
):
failing = (workspace / "failing.py").resolve()
failing.write_text("not actually python", encoding="utf-8")
Expand Down