-
Notifications
You must be signed in to change notification settings - Fork 884
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
Conversation
2aba719
to
dbc06fe
Compare
# 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 |
There was a problem hiding this comment.
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.
dbc06fe
to
1c03f47
Compare
tests/unittests/cmd/test_main.py
Outdated
# 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={}) |
There was a problem hiding this comment.
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?
# 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={}) |
1c03f47
to
aad5042
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
Proposed Commit Message
Additional Context
Test Steps
Merge type