Skip to content

Commit 807c913

Browse files
hanwen-clustergmarciani
authored andcommitted
[unit-tests] Fix unit tests on Python 3.12
Error output on Python <= 3.11: ``` error: argument --node-type: invalid choice: 'invalid' (choose from 'HeadNode', 'ComputeNode', 'LoginNode') ``` Error output on Python 3.12: ``` error: argument --node-type: invalid choice: 'invalid' (choose from HeadNode, ComputeNode, LoginNode ``` Therefore, this commit uses regex to add more flexibility to the tests Signed-off-by: Hanwen <hanwenli@amazon.com>
1 parent fb76429 commit 807c913

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cli/tests/pcluster/cli/test_describe_cluster_instances.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
66
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
77
# limitations under the License.
8+
import re
9+
810
import pytest
911
from assertpy import assert_that
1012

@@ -24,8 +26,8 @@ def test_helper(self, test_datadir, run_cli, assert_out_err):
2426
(["--cluster-name", "cluster", "--invalid"], "Invalid arguments ['--invalid']"),
2527
(
2628
["--cluster-name", "cluster", "--node-type", "invalid"],
27-
"error: argument --node-type: invalid choice: 'invalid' (choose from 'HeadNode', 'ComputeNode', "
28-
"'LoginNode')",
29+
r"error: argument --node-type: invalid choice: 'invalid' \(choose from .*HeadNode.*, .*ComputeNode.*, "
30+
r".*LoginNode.*\)",
2931
),
3032
(
3133
["--cluster-name", "cluster", "--region", "eu-west-"],
@@ -38,4 +40,4 @@ def test_invalid_args(self, args, error_message, run_cli, capsys):
3840
run_cli(command, expect_failure=True)
3941

4042
out, err = capsys.readouterr()
41-
assert_that(out + err).contains(error_message)
43+
assert_that(re.search(error_message, out + err) or error_message in out + err).is_true()

cli/tests/pcluster/cli/test_list_images.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
66
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
77
# limitations under the License.
8+
import re
9+
810
import pytest
911
from assertpy import assert_that
1012

@@ -33,7 +35,8 @@ def test_helper(self, test_datadir, run_cli, assert_out_err):
3335
),
3436
(
3537
["--image-status", "invalid"],
36-
"argument --image-status: invalid choice: 'invalid' (choose from 'AVAILABLE', 'PENDING', 'FAILED')",
38+
r"argument --image-status: invalid choice: 'invalid' "
39+
r"\(choose from .*AVAILABLE.*, .*PENDING.*, .*FAILED.*\)",
3740
),
3841
(
3942
["--image-status", "AVAILABLE", "--invalid"],
@@ -50,7 +53,7 @@ def test_invalid_args(self, args, error_message, run_cli, capsys):
5053
run_cli(command, expect_failure=True)
5154

5255
out, err = capsys.readouterr()
53-
assert_that(out + err).contains(error_message)
56+
assert_that(re.search(error_message, out + err) or error_message in out + err).is_true()
5457

5558
def test_execute(self, mocker):
5659
response_dict = {

0 commit comments

Comments
 (0)