businho / pytest-ruff

MIT License
25 stars 10 forks source link

Parse error of ruff.toml silently ignored #22

Closed mmatthe closed 6 days ago

mmatthe commented 1 month ago

When the ruff.toml file contains syntax errors which cannot be parsed, the ruff checks are silently ignored and no error is printed when run via pytest --ruff:

$ cat ruff.toml                                                                                1 ↵
llline-length = 95    # erroneous keyword llline-length

[lint]
select = ["E", "F", "W"]
ignore = ["E241", "E226", "E402"]
preview = true
$ cat pytest.ini 
[pytest]
addopts = --ruff .
$ cat a.py 
#!/usr/bin/env python3
import sys

print("hi")
$ ruff check                                                                                   1 ↵
ruff failed
  Cause: Failed to parse /tmp/ttt/ruff.toml
  Cause: TOML parse error at line 1, column 1
  |
1 | llline-length = 95
  | ^^^^^^^^^^^^^^^^^^
unknown field `llline-length`
$ pytest .                                                                                     2 ↵
======================================================== test session starts ========================================================
platform linux -- Python 3.12.1, pytest-8.2.1, pluggy-1.5.0
rootdir: /tmp/ttt
configfile: pytest.ini
plugins: ruff-0.3.2
collected 1 item                                                                                                                    

a.py .                                                                                                                        [100%]

========================================================= 1 passed in 0.01s ==

I would expect that the user is shown the error message from ruff itself. Otherwise, an erroneous ruff.toml file will disable any ruff checks.

iurisilvio commented 1 month ago

Yes, I have to check for configuration error (exit code = 2). I'll do it soon (or PR welcome).

Thanks for the report!

osvenskan commented 6 days ago

+1 for checking the return code when ruff is executed. As reported in #23, pytest-ruff isn't compatible with ruff ≥ 0.5.0. I discovered that because ruff check finds plenty of things to complain about in my source code, but ruff doesn't complain when invoked as part of pytest. I'm pretty sure it's because ruff quits on invocation and sends nothing to stdout, so pytest-ruff interprets that as passing.

iurisilvio commented 6 days ago

Fixed and released as 0.4.0!