Skip to content

test: Convert test_registry.py from unittest to pytest#6479

Merged
aciba90 merged 1 commit into
canonical:mainfrom
GautamThorani:pytest-registry-migration
Sep 22, 2025
Merged

test: Convert test_registry.py from unittest to pytest#6479
aciba90 merged 1 commit into
canonical:mainfrom
GautamThorani:pytest-registry-migration

Conversation

@GautamThorani
Copy link
Copy Markdown
Contributor

Refactored tests/unittests/test_registry.py to use pytest instead of unittest.TestCase as part of the pytest migration effort.

  • Removed TestCase inheritance and replaced with pytest fixtures
  • Converted self.assert* methods to bare assert statements
  • Replaced self.assertRaises with pytest.raises context manager
  • Added autouse fixture to reset global state
  • Maintained all original test functionality

Related: #6427

@aciba90 aciba90 self-assigned this Sep 22, 2025
Copy link
Copy Markdown
Contributor

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

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

The test migration looks good, only one comment about the superfluous fixture, thanks!

Comment thread tests/unittests/test_registry.py Outdated
class TestDictRegistry(TestCase):
class TestDictRegistry:
@pytest.fixture(autouse=True)
def reset_global_state(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't immediately see the need for this fixture. I think the fixture can be removed.

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.

Okay i will remove it and push it again. Should I create a new branch or just update this branch?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update this branch, thanks.

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.

Just did that., thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are some lint errors, you can test it locally with tox -e do_format, Could you please fix them?

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 fixed them can you check. thanks

@GautamThorani GautamThorani force-pushed the pytest-registry-migration branch from a1b6428 to 5d58760 Compare September 22, 2025 14:19
Refactored tests/unittests/test_registry.py to use pytest instead of
unittest.TestCase as part of the pytest migration effort.

- Removed TestCase inheritance and replaced with pytest fixtures
- Converted self.assert* methods to bare assert statements
- Replaced self.assertRaises with pytest.raises context manager
- Removed unnessary global state reset fixture (per review feedback)
- Maintained all original test functionality

Related: canonical#6427
@GautamThorani GautamThorani force-pushed the pytest-registry-migration branch from 5d58760 to 01e796a Compare September 22, 2025 15:04
Copy link
Copy Markdown
Contributor

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@aciba90 aciba90 merged commit 41c8ae1 into canonical:main Sep 22, 2025
21 checks passed
@GautamThorani GautamThorani deleted the pytest-registry-migration branch September 22, 2025 16:22
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Nov 17, 2025
Refactored tests/unittests/test_registry.py to use pytest instead of
unittest.TestCase as part of the pytest migration effort.

- Removed TestCase inheritance and replaced with pytest fixtures
- Converted self.assert* methods to bare assert statements
- Replaced self.assertRaises with pytest.raises context manager
- Removed unnessary global state reset fixture (per review feedback)
- Maintained all original test functionality

Related: canonical#6427
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Dec 3, 2025
Refactored tests/unittests/test_registry.py to use pytest instead of
unittest.TestCase as part of the pytest migration effort.

- Removed TestCase inheritance and replaced with pytest fixtures
- Converted self.assert* methods to bare assert statements
- Replaced self.assertRaises with pytest.raises context manager
- Removed unnessary global state reset fixture (per review feedback)
- Maintained all original test functionality

Related: canonical#6427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants