The zwave integration still contains unittest.TestCase based unit tests. We want to rewrite them to standalone pytest test functions.
The Home Assistant core standard is to write tests as standalone pytest test functions. We still have some old tests that are based on unittest.TestCase. We want all these tests to be rewritten as pytest test functions.
Here are the docs for pytest: https://docs.pytest.org/en/stable/
Here's an example of an async pytest test function in Home Assistant core:
There are many pytest fixtures to help writing the tests. See:
hass which will set up a HomeAssistant instance and start it.Here's an example of a pull request that rewrote a module of unittest.TestCase tests to standalone pytest test functions:
https://github.com/home-assistant/core/pull/40749
Here's an example command to run a single test module with pytest inside tox on Python 3.8:
tox -e py38 -- --cov-report term-missing --cov=homeassistant.components.command_line.switch tests/components/command_line/test_switch.py
It will print coverage information with lines that are missing coverage.
I made a pass at this linked above by using pytest.fixture instead of the setup and teardown method. Happy to submit a PR if this is the kind of thing you were looking for.
Refactored node entity tests in #41239
@jeffaudio please make a PR so we can see what you did.
Submitted the PR as requested. Looks like there's another one out there so feel that took a slightly different route so feel free to close mine if it's not what you wanted.
I'm working on test_init.py, that seems to be the only one left with unittest.TestCase inside.