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

Parse error of ruff.toml silently ignored #22

Closed
mmatthe opened this issue May 30, 2024 · 3 comments · Fixed by #25
Closed

Parse error of ruff.toml silently ignored #22

mmatthe opened this issue May 30, 2024 · 3 comments · Fixed by #25

Comments

@mmatthe
Copy link

mmatthe commented May 30, 2024

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
Copy link
Contributor

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

Thanks for the report!

@osvenskan
Copy link

+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
Copy link
Contributor

Fixed and released as 0.4.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants