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

Print error messages to stderr #102

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sphinxlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def job_count(values):
try:
enabled_checkers = {all_checkers[name] for name in enabled_checkers_names}
except KeyError as err:
print(f"Unknown checker: {err.args[0]}.")
print(f"Unknown checker: {err.args[0]}.", file=sys.stderr)
sys.exit(2)
return enabled_checkers, args

Expand Down Expand Up @@ -195,7 +195,7 @@ def print_errors(errors):
"""Print errors (or a message if nothing is to be printed)."""
qty = 0
for error in errors:
print(error)
print(error, file=sys.stderr)
qty += 1
if qty == 0:
print("No problems found.")
Expand All @@ -221,7 +221,7 @@ def main(argv=None):

for path in args.paths:
if not os.path.exists(path):
print(f"Error: path {path} does not exist")
print(f"Error: path {path} does not exist", file=sys.stderr)
return 2

todo = [
Expand Down
18 changes: 9 additions & 9 deletions tests/test_sphinxlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_sphinxlint_shall_trigger_false_positive(file, capsys):
assert not has_errors
has_errors = main(["sphinxlint.py", "--enable", "all", str(file)])
out, err = capsys.readouterr()
assert err == ""
assert out != "No problems found.\n"
assert err != ""
assert has_errors


Expand All @@ -54,17 +54,17 @@ def test_sphinxlint_shall_not_pass(file, expected_errors, capsys):
has_errors = main(["sphinxlint.py", "--enable", "all", file])
out, err = capsys.readouterr()
assert out != "No problems found.\n"
assert err == ""
assert err != ""
assert has_errors
assert expected_errors, (
"That's not OK not to tell which errors are expected, "
"""add one using a ".. expect: " line."""
)
for expected_error in expected_errors:
assert expected_error in out
assert expected_error in err
number_of_expected_errors = len(expected_errors)
number_of_reported_errors = len(out.splitlines())
assert number_of_expected_errors == number_of_reported_errors, f"{number_of_reported_errors=}, {out=}"
number_of_reported_errors = len(err.splitlines())
assert number_of_expected_errors == number_of_reported_errors, f"{number_of_reported_errors=}, {err=}"


@pytest.mark.parametrize("file", [str(FIXTURE_DIR / "paragraphs.rst")])
Expand All @@ -84,8 +84,8 @@ def test_paragraphs(file):
def test_line_no_in_error_msg(file, capsys):
has_errors = main(["sphinxlint.py", file])
out, err = capsys.readouterr()
assert err == ""
assert "paragraphs.rst:76: role missing colon before" in out
assert "paragraphs.rst:70: role use a single backtick" in out
assert "paragraphs.rst:65: inline literal missing (escaped) space" in out
assert out == ""
assert "paragraphs.rst:76: role missing colon before" in err
assert "paragraphs.rst:70: role use a single backtick" in err
assert "paragraphs.rst:65: inline literal missing (escaped) space" in err
assert has_errors