canonical / canonical/pycloudlib
Refactor: Convert unittest to pytest in tests/unit_tests/test_helpers.py
- Dominant language
- Python
- Stars
- 22
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
This task involves converting the tests within tests/unit_tests/test_cloud.py from unittest.TestCase-based tests to the pytest functional style.
Instructions for Copilot/Assignee:
1. Remove TestCase Inheritance: Convert test classes inheriting from unittest.TestCase into regular Python classes or simply remove the classes and use standalone functions.
2. Convert Assertions: Replace self.assertEqual(...), self.assertTrue(...), etc., with standard assert statements. pytest automatically handles assertion rewriting.
3.Refactor Setup/Teardown:
- Move setUp() methods to pytest.fixture functions.
- Move tearDown() methods to finalizers in fixtures using yield or addfinalizer.
4. Use mocker instead or mock.patch or mock.call
5.Handle Exceptions: Replace self.assertRaises(...) with pytest.raises(...) as a context manager.
Acceptance criteria:
- no remaining self.assert*, mock.call or mock.patch uses
- no setUp or teadDown methods
- If common mocks are used for most tests in a class, ensure the test class has a common setup_mocks fixture
- Ensure proper format is applied by running `tox -e format`
- Run Tests: Ensure all tests with `tox -e pytest` in the root directory
- Semantic version PATCH value must be incremented in pycloudlib/VERSION
- Ensure all github workflows succeed
- The final squashed changset should be a single git commit which contains the footer 'Fixes GH-'
Contributor guide
Assessment
This issue has not been assessed yet.