Skip to content

gh-120417: Add #noqa to load_tests() in tests #120626

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

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 17, 2024

Ignore linter "imported but unused" warnings in tests when the linter doesn't understand why the import is important.

@encukou
Copy link
Member

encukou commented Jun 17, 2024

Could you add/link an explanation about what noqa: F401 means and how to maintain it?

In my projects, I've avoided these warning by adding public names to __all__, rather than with a cryptic comment.

@vstinner
Copy link
Member Author

Could you add/link an explanation about what noqa: F401 means and how to maintain it?

It's a "standard" linter command to ignore "imported but unused" warning on the current line.

It was discussed at #120421.

@serhiy-storchaka
Copy link
Member

Could you add an exception for load_tests in a global configuration file?

@vstinner
Copy link
Member Author

@serhiy-storchaka:

Could you add an exception for load_tests in a global configuration file?

I have no idea on how to do that.

@AlexWaygood: Is it something supported by Ruff by example?

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 17, 2024

@AlexWaygood: Is it something supported by Ruff by example?

we support ignoring certain errors for filenames that match certain patterns. But I don't think we support ignoring F401 for specific symbols, no. It might be a reasonable feature request.

@serhiy-storchaka
Copy link
Member

Can it be ignored for Lib/test/*/**/__main__.py? All these files are the same.

@AlexWaygood
Copy link
Member

Yes, in Ruff you can do that via the CLI using --config='lint.per-file-ignores = {"Lib/test/*/**/__main__.py" = ["F401"]}'. Or in a pyproject.toml configuration file, you can do this:

[tool.ruff.lint.per-file-ignores]
"Lib/test/*/**/__main__.py" = ["F401"]

Or this in a ruff.toml configuration file:

[lint.per-file-ignores]
"Lib/test/*/**/__main__.py" = ["F401"]

@vstinner
Copy link
Member Author

vstinner commented Jun 17, 2024

Can it be ignored for Lib/test/*/**/__main__.py? All these files are the same.

It means that other unused imports can no longer be catched.

@vstinner
Copy link
Member Author

In total, ruff check|grep F401 returns 173 lines. These load_tests are not the worst, so I prefer to close this PR for now.

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

Successfully merging this pull request may close these issues.

4 participants