Skip to content

Conversation

@MoeSalah1999
Copy link
Contributor

@MoeSalah1999 MoeSalah1999 commented Dec 12, 2025

Proposed Commit Message




tests: Converted test_cc_rsyslog.py from unittest to pytest. 
-made sure test case classes don't inherit from TestCase 
-used pytest fixtures instead of unittest setUp method 
-converted all self.assert to plain assert.
Related GH-6427 

Additional Context

Test Steps

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@MoeSalah1999
Copy link
Contributor Author

@blackboxsw could you please verify this?

Copy link
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.

@MoeSalah1999 please follow https://docs.cloud-init.io/en/latest/development/index.html which documents running tox-e format .

Also:
I don't think basecfg or bsdcfg need to be fixtures, it's also not good practice to share mutable fixtures when the individual tests modify that mutable structure as it'll lead to intermittent test failures when running tests in parallel. Since they are just plain dicts that do not require resource setup, how about just define them as class-level attributes which are manipulated via copy.deepcopy before updating.



@pytest.fixture
def temp_dir():
Copy link
Collaborator

Choose a reason for hiding this comment

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

pytest already has a tmpdir fixture, not need to define our own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clearing that up and for the guidance! I made all the changes you requested, please verify them at your convenience.

@blackboxsw
Copy link
Collaborator

Additionally please format the proposed commit message suggestion to correctly represent conventional commits.
The line-length is too long for our commit messages.

And the footer of a commit message should not say Fixes GH-6427 unless that full issue was resolved for all cases.
Instead use Related GH-6427 please.

@blackboxsw blackboxsw self-assigned this Dec 17, 2025
(os.path.join(temp_dir, "default.cfg"), "*.* foohost\n"),
(os.path.join(temp_dir, "my.cfg"), "abc\n"),
(os.path.join(temp_dir, "mydir/mycfg"), "filefoo-content\n"),
(os.path.join(tmpdir, "default.cfg"), "*.* foohost\n"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for this nit, tmpdir already provides a tmpdir.join method, so we don't need the extra os.path.join calls throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I was so eager to make that change, but I didn't wanna mess with anything other than what you instructed me to do. I'll get right on it.

Copy link
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.

Please use tmpdir.join where possible otherwise looks good to me. Thank you!

@MoeSalah1999 MoeSalah1999 force-pushed the pytestify-test_cc_rsyslog.py branch from 1e396a6 to 29282d5 Compare December 19, 2025 00:13
Comment on lines 91 to 92
cfg = copy.deepcopy(self.BSDCFG)

Copy link
Collaborator

Choose a reason for hiding this comment

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

self.BSDCFG doesn't appear to be manipulated in this test. So you can just use it directly on line 98, no need to deepcopy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a suggestion, how about I construct a fresh dict literal in this test only, to avoid silently re-introducing shared mutable states, and to not lose protection against implementation changes in load_config().

):
cloud = get_cloud(distro="freebsd", metadata={})
self.assertEqual(load_config({}, distro=cloud.distro), self.bsdcfg)
assert load_config({}, distro=cloud.distro) == cfg
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert load_config({}, distro=cloud.distro) == cfg
assert load_config({}, distro=cloud.distro) == self.BSDCFG

fname = os.path.join(self.tmp, "foo.cfg")
self.assertEqual([fname], changed)
self.assertEqual(util.load_text_file(fname), cfgline + "\n")
fname = tmpdir.join("foo.cfg")
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's just str(....) up here insetad of at the two callsites using fname below

Suggested change
fname = tmpdir.join("foo.cfg")
fname = str(tmpdir.join("foo.cfg"))

Copy link
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 @MoeSalah1999 again. two minor nits and we'll land this.

Copy link
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.

Ship it! Thanks again @MoeSalah1999

@blackboxsw blackboxsw merged commit 3067c25 into canonical:main Dec 19, 2025
20 checks passed
holmanb pushed a commit that referenced this pull request Feb 5, 2026
-made sure test case classes don't inherit from TestCase
-used pytest fixtures instead of unittest setUp method
-converted all self.assert to plain assert.

Related GH-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