mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 04:05:20 +01:00
Add check for usefixtures decorator in pylint plugin (#118456)
This commit is contained in:
@@ -1152,16 +1152,20 @@ def test_pytest_function(
|
||||
def test_pytest_invalid_function(
|
||||
linter: UnittestLinter, type_hint_checker: BaseChecker
|
||||
) -> None:
|
||||
"""Ensure invalid hints are rejected for async_get_service."""
|
||||
func_node, hass_node, caplog_node = astroid.extract_node(
|
||||
"""
|
||||
"""Ensure invalid hints are rejected for a test function."""
|
||||
func_node, hass_node, caplog_node, first_none_node, second_none_node = (
|
||||
astroid.extract_node(
|
||||
"""
|
||||
async def test_sample( #@
|
||||
hass: Something, #@
|
||||
caplog: SomethingElse, #@
|
||||
current_request_with_host, #@
|
||||
enable_custom_integrations: None, #@
|
||||
) -> Anything:
|
||||
pass
|
||||
""",
|
||||
"tests.components.pylint_test.notify",
|
||||
"tests.components.pylint_test.notify",
|
||||
)
|
||||
)
|
||||
type_hint_checker.visit_module(func_node.parent)
|
||||
|
||||
@@ -1194,6 +1198,33 @@ def test_pytest_invalid_function(
|
||||
end_line=4,
|
||||
end_col_offset=25,
|
||||
),
|
||||
pylint.testutils.MessageTest(
|
||||
msg_id="hass-consider-usefixtures-decorator",
|
||||
node=first_none_node,
|
||||
args=("current_request_with_host", "None", "test_sample"),
|
||||
line=5,
|
||||
col_offset=4,
|
||||
end_line=5,
|
||||
end_col_offset=29,
|
||||
),
|
||||
pylint.testutils.MessageTest(
|
||||
msg_id="hass-argument-type",
|
||||
node=first_none_node,
|
||||
args=("current_request_with_host", "None", "test_sample"),
|
||||
line=5,
|
||||
col_offset=4,
|
||||
end_line=5,
|
||||
end_col_offset=29,
|
||||
),
|
||||
pylint.testutils.MessageTest(
|
||||
msg_id="hass-consider-usefixtures-decorator",
|
||||
node=second_none_node,
|
||||
args=("enable_custom_integrations", "None", "test_sample"),
|
||||
line=6,
|
||||
col_offset=4,
|
||||
end_line=6,
|
||||
end_col_offset=36,
|
||||
),
|
||||
):
|
||||
type_hint_checker.visit_asyncfunctiondef(func_node)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user