Skip to content

Conversation

@AzizCode92
Copy link
Contributor

@AzizCode92 AzizCode92 commented Aug 22, 2025

Purpose

In the test_bigger_truncation_size test, the 'err' variable from the pytest.raises context manager was being incorrectly reassigned by the API call.

Because the await client.post(...) line raises an exception as expected, the assert statement on the following line was unreachable and never executed. This means the test was only verifying the exception type, not the content of the error message.

This commit fixes the test to correctly handle the exception. The API call is now made without assignment, and the assertion is moved outside the with block, checking err.value to inspect the actual exception instance. This ensures the test is robust and properly verifies the error message content.

Test Plan

Test Result

(Optional) Documentation Update


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

In the test_bigger_truncation_size test, the 'err' variable from the pytest.raises context manager was being incorrectly reassigned by the API call.

Because the `await client.post(...)` line raises an exception as expected, the `assert` statement on the following line was unreachable and never executed. This meant the test was only verifying the exception type, not the content of the error message.

This commit refactors the test to correctly handle the exception. The API call is now made without assignment, and the assertion is moved outside the `with` block, checking `err.value` to inspect the actual exception instance. This ensures the test is robust and properly verifies the error message content.

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 22, 2025 12:04
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an unreachable assertion in the test_bigger_truncation_size test. The change ensures that the test now properly verifies the exception raised for invalid truncation sizes. I have one suggestion to improve the robustness of the assertion by checking the structured error data instead of performing a brittle string comparison on the exception's text representation. This will make the test more resilient to future formatting changes.

Comment on lines 81 to 88
assert str(err.value) == f"""openai.BadRequestError:
Error code: 400 - {{'object': 'error',
'message': 'truncate_prompt_tokens value
({truncation_size})
is greater than max_model_len ({max_model_len}).
Please, select a smaller truncation size.',
'type': 'BadRequestError',
'param': None, 'code': 400}}"""
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While this change correctly fixes the test's logic, asserting against the exact string representation of the exception is brittle. The test could fail due to minor, unrelated changes in whitespace or formatting within the openai library's BadRequestError.__str__ method or vLLM's error message.

A more robust approach is to inspect the structured error data from the exception object. This makes the test resilient to formatting changes and more clearly expresses the intent of what is being tested.

    assert err.value.http_status == 400

    # The error from the server is nested under the 'error' key in the response body.
    error_details = err.value.body["error"]

    assert error_details["type"] == "BadRequestError"
    assert error_details["code"] == 400

    # The underlying ValueError is a single-line string. Comparing against
    # that is more robust than a multi-line string sensitive to indentation.
    expected_message = (f"truncate_prompt_tokens value "
                        f"({truncation_size}) "
                        f"is greater than max_model_len ({max_model_len}). "
                        f"Please, select a smaller truncation size.")
    assert error_details["message"] == expected_message

@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 22, 2025
Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
auto-merge was automatically disabled August 22, 2025 12:19

Head branch was pushed to by a user without write access

@DarkLight1337
Copy link
Member

The test fails now, PTAL

@DarkLight1337
Copy link
Member

Probably it is better to parse the error message as suggested by Gemini

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 22, 2025 14:55
@AzizCode92
Copy link
Contributor Author

Will fix it again.

@AzizCode92
Copy link
Contributor Author

Fixing my local setup to run the test on my end before pushing here again

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
auto-merge was automatically disabled August 22, 2025 22:18

Head branch was pushed to by a user without write access

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 23, 2025 04:12
@DarkLight1337 DarkLight1337 merged commit d9a5520 into vllm-project:main Aug 23, 2025
17 checks passed
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
xiao-llm pushed a commit to xiao-llm/vllm that referenced this pull request Aug 28, 2025
…oject#23425)

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
Signed-off-by: Xiao Yu <xiao.yu@amd.com>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
mengxingkongzhouhan pushed a commit to mengxingkongzhouhan/vllm that referenced this pull request Aug 30, 2025
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Sep 3, 2025
ekagra-ranjan pushed a commit to ekagra-ranjan/vllm that referenced this pull request Sep 4, 2025
…oject#23425)

Signed-off-by: AzizCode92 <azizbenothman76@gmail.com>
Signed-off-by: Ekagra Ranjan <3116519+ekagra-ranjan@users.noreply.github.com>
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants