Navigation Menu

Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite mochad unittest to pytest style #42164

Merged
merged 2 commits into from Oct 22, 2020

Conversation

tim-werner
Copy link
Contributor

Breaking change

Proposed change

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

assert await async_setup_component(hass, light.DOMAIN, good_config)


@pytest.mark.parametrize("brightness", [32, 256, 64])
Copy link
Member

Choose a reason for hiding this comment

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

Why is this parametrized ?

Suggested change
@pytest.mark.parametrize("brightness", [32, 256, 64])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Parameterizing this test makes no sense. I will remove the test anyway (see below).



@pytest.mark.parametrize("brightness", [32, 256, 64])
async def test_name(light_mock):
Copy link
Member

Choose a reason for hiding this comment

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

This test is 馃し I think that we can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think we can remove this test. I did keep all the test that have been there before. Did not want to remove any test

assert "fake_light" == light_mock.name


@pytest.mark.parametrize(
Copy link
Member

Choose a reason for hiding this comment

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

This makes no sense either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have combined the 3 old tests that have tested different light levels into one parametrized. The 3 old test have basically tested the same thing with different light levels. If this does not make sense we can replace these tests with more meaningful tests but I did not want to remove any test that was there before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am also confused why the test returns on with light level 32 and xdim with different light levels. However, this was also the case for the old tests. I would expect a more consistence behavior ..

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I didn't realize that you could parametrize stuff in fixtures. TIL!

Dev automation moved this from Needs review to Review in progress Oct 22, 2020
Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

These tests and the parametrizations don't seem to match up .

@MartinHjelmare MartinHjelmare changed the title rewrite mochad unittest to pytest style Rewrite mochad unittest to pytest style Oct 22, 2020
Copy link
Contributor Author

@tim-werner tim-werner left a comment

Choose a reason for hiding this comment

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

Thanks for reviewing. In general I did not want to remove any test that have been there before. Not sure if the tests make that much sense ...



@pytest.mark.parametrize("brightness", [32, 256, 64])
async def test_name(light_mock):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think we can remove this test. I did keep all the test that have been there before. Did not want to remove any test

assert "fake_light" == light_mock.name


@pytest.mark.parametrize(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have combined the 3 old tests that have tested different light levels into one parametrized. The 3 old test have basically tested the same thing with different light levels. If this does not make sense we can replace these tests with more meaningful tests but I did not want to remove any test that was there before

assert await async_setup_component(hass, light.DOMAIN, good_config)


@pytest.mark.parametrize("brightness", [32, 256, 64])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Parameterizing this test makes no sense. I will remove the test anyway (see below).

@tim-werner
Copy link
Contributor Author

These tests and the parametrizations don't seem to match up .

Hi, I think the confusions comes due to the way how it is parameterized. The brightness in the @pytest.mark.parametrize will affect the brightness in the light_mock fixture. It would be nicer to parameterize the brigthness in the fixture itself however I do not know a good way to combine the expected values (because it will create a test matrix combining each expected with each brightness parameter)

Dev automation moved this from Review in progress to Reviewer approved Oct 22, 2020
@balloob balloob merged commit fcc895f into home-assistant:dev Oct 22, 2020
Dev automation moved this from Reviewer approved to Done Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Rewrite mochad unittest tests to pytest style test functions
3 participants