Skip to content

test(config): Convert test_cc_spacewalk.py from unittest to pytest#6515

Merged
blackboxsw merged 1 commit into
canonical:mainfrom
Pneha1234:pytest-convert-test-spacewalk
Oct 21, 2025
Merged

test(config): Convert test_cc_spacewalk.py from unittest to pytest#6515
blackboxsw merged 1 commit into
canonical:mainfrom
Pneha1234:pytest-convert-test-spacewalk

Conversation

@Pneha1234
Copy link
Copy Markdown
Contributor

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

  • Removed TestCase inheritance
  • Removed unused helpers import
  • Converted self.assertFalse() to assert not statement
  • Converted self.assertTrue() to assert statement
  • Maintained all original test functionality

Related: #6427

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thank you for your additional contributions. Just a minor nit since we know exactly what we should be returning as a boolean.

def test_not_is_registered(self, mock_subp):
mock_subp.side_effect = subp.ProcessExecutionError(exit_code=1)
self.assertFalse(cc_spacewalk.is_registered())
assert not cc_spacewalk.is_registered()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for this. Minor preference: Let's be a bit more strict about this return type of is_registered avoid truthy behavior and just strictly assert that we returned False. I don't want this test to pass if we start returning an empty dict or string in the future because we have changed the API.

Suggested change
assert not cc_spacewalk.is_registered()
assert cc_spacewalk.is_registered() is False

Same comment below please.

def test_is_registered(self, mock_subp):
mock_subp.side_effect = None
self.assertTrue(cc_spacewalk.is_registered())
assert cc_spacewalk.is_registered()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert cc_spacewalk.is_registered()
assert cc_spacewalk.is_registered() is True

@Pneha1234 Pneha1234 force-pushed the pytest-convert-test-spacewalk branch from ad60898 to 8485586 Compare October 20, 2025 04:12
@Pneha1234
Copy link
Copy Markdown
Contributor Author

@blackboxsw Updated! Changed to use strict identity checks (is True / is False. Thanks for catching that!

@Pneha1234 Pneha1234 force-pushed the pytest-convert-test-spacewalk branch from 8485586 to f426d47 Compare October 20, 2025 05:46
Refactored tests/unittests/config/test_cc_spacewalk.py to use pytest instead of unittest.TestCase as part of the pytest migration effort.

- Removed TestCase inheritance
- Removed unused helpers import
- Converted self.assertFalse() to strict boolean check (is False)
- Converted self.assertTrue() to strict boolean check (is True)
- Maintained all original test functionality

Related: canonical#6427
@Pneha1234 Pneha1234 force-pushed the pytest-convert-test-spacewalk branch from f426d47 to 579b8c9 Compare October 20, 2025 05:49
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Looking great! Thanks again.

@blackboxsw blackboxsw merged commit 9db1cc8 into canonical:main Oct 21, 2025
21 checks passed
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Dec 12, 2025
…anonical#6515)

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

- Removed TestCase inheritance
- Removed unused helpers import
- Converted self.assertFalse() to strict boolean check (is False)
- Converted self.assertTrue() to strict boolean check (is True)
- Maintained all original test functionality

Related: canonical#6427
holmanb pushed a commit that referenced this pull request Dec 18, 2025
…6515)

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

- Removed TestCase inheritance
- Removed unused helpers import
- Converted self.assertFalse() to strict boolean check (is False)
- Converted self.assertTrue() to strict boolean check (is True)
- Maintained all original test functionality

Related: #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