Skip to content

Commit ac9d13a

Browse files
authored
Print error messages to stderr (#102)
1 parent 6b070ea commit ac9d13a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

sphinxlint/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def job_count(values):
138138
try:
139139
enabled_checkers = {all_checkers[name] for name in enabled_checkers_names}
140140
except KeyError as err:
141-
print(f"Unknown checker: {err.args[0]}.")
141+
print(f"Unknown checker: {err.args[0]}.", file=sys.stderr)
142142
sys.exit(2)
143143
return enabled_checkers, args
144144

@@ -195,7 +195,7 @@ def print_errors(errors):
195195
"""Print errors (or a message if nothing is to be printed)."""
196196
qty = 0
197197
for error in errors:
198-
print(error)
198+
print(error, file=sys.stderr)
199199
qty += 1
200200
if qty == 0:
201201
print("No problems found.")
@@ -221,7 +221,7 @@ def main(argv=None):
221221

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

227227
todo = [

tests/test_sphinxlint.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def test_sphinxlint_shall_trigger_false_positive(file, capsys):
2929
assert not has_errors
3030
has_errors = main(["sphinxlint.py", "--enable", "all", str(file)])
3131
out, err = capsys.readouterr()
32-
assert err == ""
3332
assert out != "No problems found.\n"
33+
assert err != ""
3434
assert has_errors
3535

3636

@@ -54,17 +54,17 @@ def test_sphinxlint_shall_not_pass(file, expected_errors, capsys):
5454
has_errors = main(["sphinxlint.py", "--enable", "all", file])
5555
out, err = capsys.readouterr()
5656
assert out != "No problems found.\n"
57-
assert err == ""
57+
assert err != ""
5858
assert has_errors
5959
assert expected_errors, (
6060
"That's not OK not to tell which errors are expected, "
6161
"""add one using a ".. expect: " line."""
6262
)
6363
for expected_error in expected_errors:
64-
assert expected_error in out
64+
assert expected_error in err
6565
number_of_expected_errors = len(expected_errors)
66-
number_of_reported_errors = len(out.splitlines())
67-
assert number_of_expected_errors == number_of_reported_errors, f"{number_of_reported_errors=}, {out=}"
66+
number_of_reported_errors = len(err.splitlines())
67+
assert number_of_expected_errors == number_of_reported_errors, f"{number_of_reported_errors=}, {err=}"
6868

6969

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

0 commit comments

Comments
 (0)