From 983e714b8daa13030503244eedd6011d334aaeab Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 17 Oct 2024 22:54:44 -0500 Subject: [PATCH 1/2] test: unbreak pytest-xdist 'pytest -n auto' fails with random data in parametrization, so work around it. --- tests/unittests/cmd/test_main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/unittests/cmd/test_main.py b/tests/unittests/cmd/test_main.py index 99a3fc670b8..940db060d70 100644 --- a/tests/unittests/cmd/test_main.py +++ b/tests/unittests/cmd/test_main.py @@ -267,12 +267,20 @@ def test_main_sys_argv( # 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), + (mock.Mock(), "RANDOM100", True), # Something small that shouldn't decode to utf-8 - (mock.Mock(), os.urandom(5), True), + (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) From a1d32525e5cf772fd59d44f2e46b8cd106c93c3e Mon Sep 17 00:00:00 2001 From: James Falcon Date: Fri, 18 Oct 2024 10:08:27 -0500 Subject: [PATCH 2/2] comments --- tests/unittests/cmd/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittests/cmd/test_main.py b/tests/unittests/cmd/test_main.py index 940db060d70..aef747e8e85 100644 --- a/tests/unittests/cmd/test_main.py +++ b/tests/unittests/cmd/test_main.py @@ -266,9 +266,9 @@ 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 + # Something that after processing won't decode to utf-8 (mock.Mock(), "RANDOM100", True), - # Something small that shouldn't decode to utf-8 + # Something small that after processing won't decode to utf-8 (mock.Mock(), "RANDOM5", True), ], )