-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Refactor config flow tests in generic camera #134385
Refactor config flow tests in generic camera #134385
Conversation
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com>
e9f19a7
to
767d2de
Compare
tests/components/generic/conftest.py
Outdated
@pytest.fixture(name="mock_setup_entry") | ||
def mock_async_setup_entry_fixture() -> _patch: | ||
"""Mock setup entry.""" | ||
return patch( | ||
"homeassistant.components.generic.async_setup_entry", | ||
return_value=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A common fixture for this is
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.airgradient.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry
This way you only need to load the fixture and its already patch. With the current solution, you would need to always do with mock_setup_entry
(and I personally try to avoid them if possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks! Yes that makes sense. Will update tonight and check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works well, thanks!
Note: That has reduced the code but resulted in a lot of outdenting in facfe9e, so the diff looks a lot bigger. I suggest reviewing with whitespace ignored:
facfe9e?w=1
Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com> Co-authored-by: Allen Porter <allen.porter@gmail.com>
Proposed change
Clean up of existing tests:
Should be no functional change and no reduction in test coverage.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: