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: unbreak pytest-xdist #5829

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions tests/unittests/cmd/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,21 @@ def test_main_sys_argv(
(mock.Mock(), "#cloud-config\nbootcmd:\necho hello", True),
# Non-cloud-config
(mock.Mock(), "#!/bin/bash\n - echo hello", True),
# Something that won't decode to utf-8
(mock.Mock(), os.urandom(100), True),
# Something small that shouldn't decode to utf-8
(mock.Mock(), os.urandom(5), True),
# Something that after processing won't decode to utf-8
(mock.Mock(), "RANDOM100", True),
Copy link
Member

Choose a reason for hiding this comment

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

This an the next don't match the comment "won't decode to utf-8".

Copy link
Member Author

Choose a reason for hiding this comment

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

Push an update

# Something small that after processing won't decode to utf-8
(mock.Mock(), "RANDOM5", True),
],
)
def test_should_wait_on_network(self, ds, userdata, expected):
# pytest-xdist doesn't like randomness
# https://github.com/pytest-dev/pytest-xdist/issues/432
# So work around it with a super stupid hack
if userdata == "RANDOM100":
userdata = os.urandom(100)
elif userdata == "RANDOM5":
userdata = os.urandom(5)

if ds:
ds.get_userdata_raw = mock.Mock(return_value=userdata)
ds.get_vendordata_raw = mock.Mock(return_value=None)
Expand Down