Skip to content

Adjust async_setup_entry in config_flow scaffold#88319

Merged
emontnemery merged 1 commit into
home-assistant:devfrom
epenet:scaffold
Feb 17, 2023
Merged

Adjust async_setup_entry in config_flow scaffold#88319
emontnemery merged 1 commit into
home-assistant:devfrom
epenet:scaffold

Conversation

@epenet
Copy link
Copy Markdown
Contributor

@epenet epenet commented Feb 17, 2023

Proposed change

Linked to #88315

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant home-assistant Bot added cla-signed code-quality small-pr PRs with less than 30 lines. labels Feb 17, 2023
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Thanks, @epenet 👍

@emontnemery emontnemery merged commit 5dda1de into home-assistant:dev Feb 17, 2023
@epenet epenet deleted the scaffold branch February 17, 2023 12:44
Comment on lines +14 to +15
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the name of the fixture is set, we also don't use the override_* naming generally... so that looks odd to me.

Why not just name the function mock_setup_entry ?

Additionally, I think it is better practice (and better readable) if these things are in conftest.py and not in top of this file (it distracts from the actual tests in this module).

../Frenck

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened #88481 to rename the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding conftest.py, I think it is clearer in this case to have it defined at the top of test_config_flow module.

  • for new contributors, it makes it an easier introduction to fixtures
  • it usually only applies to config flow tests
  • we can't use autouse=True: we have to add the fixture to conftest, and then add a specific pytestmark = pytest.mark.usefixtures("mock_setup_entry") at the top of the test file
  • we have to add a new file to the scaffold

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno, this will now result in a review comment 9 out of 10 times asking to move it, which is also not great 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened an alternative PR #88484

Copy link
Copy Markdown
Contributor

@elupus elupus Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, name is set so function def can differ from fixture name. If fixture name is in same as function name, you get a linting warning on the test cases that a testcase parameter hides a function.

Same issue will occur if a fixture uses another fixture inside conftest.

Ps. Since that lint warning can easily be ignore and is not enforced anywhere, im perfectly fine with either changes for my modules.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, name is set so function def can differ from fixture name.

I'm aware, although, it isn't an issue and we have explicitly disabled those linting checks. Nevertheless, in general we use the _fixture postfix to resolve such cases.

AlePerla pushed a commit to AlePerla/homeassistant_core that referenced this pull request Feb 17, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed code-quality small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants