Skip to content

Commit

Permalink
[unit-tests] Fix unit tests on Python 3.12
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hanwen-cluster committed Dec 19, 2024
1 parent a839865 commit 45a0038
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cli/tests/pcluster/cli/test_describe_cluster_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
# limitations under the License.
import re

import pytest
from assertpy import assert_that

Expand All @@ -24,8 +26,8 @@ def test_helper(self, test_datadir, run_cli, assert_out_err):
(["--cluster-name", "cluster", "--invalid"], "Invalid arguments ['--invalid']"),
(
["--cluster-name", "cluster", "--node-type", "invalid"],
"error: argument --node-type: invalid choice: 'invalid' (choose from 'HeadNode', 'ComputeNode', "
"'LoginNode')",
r"error: argument --node-type: invalid choice: 'invalid' \(choose from .HeadNode., .ComputeNode., "
r".LoginNode.\)",
),
(
["--cluster-name", "cluster", "--region", "eu-west-"],
Expand All @@ -38,4 +40,4 @@ def test_invalid_args(self, args, error_message, run_cli, capsys):
run_cli(command, expect_failure=True)

out, err = capsys.readouterr()
assert_that(out + err).contains(error_message)
assert_that(re.search(error_message, out + err) or error_message in out + err).is_true()
6 changes: 4 additions & 2 deletions cli/tests/pcluster/cli/test_list_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
# limitations under the License.
import re

import pytest
from assertpy import assert_that

Expand Down Expand Up @@ -33,7 +35,7 @@ def test_helper(self, test_datadir, run_cli, assert_out_err):
),
(
["--image-status", "invalid"],
"argument --image-status: invalid choice: 'invalid' (choose from 'AVAILABLE', 'PENDING', 'FAILED')",
r"argument --image-status: invalid choice: 'invalid' \(choose from .AVAILABLE., .PENDING., .FAILED.\)",
),
(
["--image-status", "AVAILABLE", "--invalid"],
Expand All @@ -50,7 +52,7 @@ def test_invalid_args(self, args, error_message, run_cli, capsys):
run_cli(command, expect_failure=True)

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

def test_execute(self, mocker):
response_dict = {
Expand Down

0 comments on commit 45a0038

Please sign in to comment.