Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: pytestify test_main.py #5758

Merged
merged 2 commits into from
Oct 1, 2024
Merged

Conversation

TheRealFalcon
Copy link
Member

@TheRealFalcon TheRealFalcon commented Sep 30, 2024

Proposed Commit Message

test: pytestify test_main.py

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>)

@TheRealFalcon TheRealFalcon changed the title test: pytestify main.py test: pytestify test_main.py Sep 30, 2024
# modules are run (including write_files)
self.assertEqual(
"blah", load_text_file(os.path.join(self.new_root, "etc/blah.ini"))
assert "set_hostname" == name
Copy link
Member Author

Choose a reason for hiding this comment

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

I did simplify the logic here and remove a lot of extraneous checks in the rest of the test. The goal of this test was to ensure that set_hostname gets called from main.py, and the rest of the checks that happened here already exist in the previous test.

Comment on lines 23 to 27
# cc_ubuntu_install module calls get_meta_doc on import.
# This call will fail if filesystem redirection mocks are in place
# and the module hasn't already been imported which can depend
# on test ordering.
mocker.patch("cloudinit.config.schema.get_meta_doc", return_value={})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that #5757 landed I think this mock can be dropped right?

Suggested change
# cc_ubuntu_install module calls get_meta_doc on import.
# This call will fail if filesystem redirection mocks are in place
# and the module hasn't already been imported which can depend
# on test ordering.
mocker.patch("cloudinit.config.schema.get_meta_doc", return_value={})

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.

LGTM. Should have hit approve

)
mocker.patch("cloudinit.cmd.main.util.get_cmdline", return_value="")
mocker.patch("cloudinit.cmd.main.util.uptime", return_value="12345")
os.environ["_CLOUD_INIT_SAVE_STDOUT"] = "true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL about avoiding the stdout/err redirect.

os.environ.pop("_CLOUD_INIT_SAVE_STDOUT")

@pytest.fixture
def cloud_cfg(self, mocker, tmpdir, fake_filesystem):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had wondered about using our paths fixture from conftest.py here. But, because of the need to ensure_dir throughout it didn't make sense.

@blackboxsw blackboxsw merged commit 9dff1af into canonical:main Oct 1, 2024
21 checks passed
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