-
Notifications
You must be signed in to change notification settings - Fork 2k
False positive F401 due to %%ipytest line in notebook #13718
Description
Keywords to find existing issue: F401 and ipytest. The following is very similar, but still different, it seems: #10454
A minimal working example would be a Jupyter notebook with the following two cells:
import ipytest
import pytest
ipytest.autoconfig()%%ipytest
def test_simple():
with pytest.raises(TypeError):
print(1 + "a")Ruff will report F401 (unused-import) for the line import pytest.
To reproduce the issue, create a notebook with the above cells, called bug.ipynb and run the command:
ruff check demos/bug.ipynb --fixI've tested with with ruff 0.6.3 and 0.6.9. I have the following in my pyproject.toml, but I don't think these settings matter:
[tool.ruff]
line-length = 100
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "UP", "B", "I", "PGH", "PL", "RUF"]
ignore = ["E741", "PLR2004", "PLR0913", "PLR0912", "PLW2901", "PLR0915"]As a workaround, one can (obviously) add a comment # noqa: F401 to the import line
When removing the line %%ipytest, the problem goes away, but it that doesn't help because the line is doing something useful.
Given the easy workaround, this is probably not urgent.
By the way, thanks for creating Ruff!