Skip to content

Commit

Permalink
test: unbreak pytest-xdist (#5829)
Browse files Browse the repository at this point in the history
'pytest -n auto' fails with random data in parametrization, so
work around it.
  • Loading branch information
TheRealFalcon committed Nov 4, 2024
1 parent d611ad2 commit ed99b93
Showing 1 changed file with 12 additions and 4 deletions.
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),
# 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

0 comments on commit ed99b93

Please sign in to comment.