Skip to content

[Lint]Style: Convert test/ to ruff format(Batch #1)#6738

Merged
wangxiyuan merged 2 commits intovllm-project:mainfrom
MrZ20:lint-test-1
Mar 10, 2026
Merged

[Lint]Style: Convert test/ to ruff format(Batch #1)#6738
wangxiyuan merged 2 commits intovllm-project:mainfrom
MrZ20:lint-test-1

Conversation

@MrZ20
Copy link
Copy Markdown
Contributor

@MrZ20 MrZ20 commented Feb 13, 2026

What this PR does / why we need it?

Scope of Changes:

File Path
tests/e2e/310p/multicard/test_vl_model_multicard.py
tests/e2e/310p/singlecard/test_vl_model_singlecard.py
tests/e2e/310p/test_utils.py
tests/e2e/conftest.py
tests/e2e/model_utils.py
tests/e2e/models/conftest.py
tests/e2e/models/test_lm_eval_correctness.py
tests/e2e/multicard/2-cards/spec_decode/test_spec_decode.py
tests/e2e/multicard/2-cards/test_aclgraph_capture_replay.py
tests/e2e/multicard/2-cards/test_data_parallel.py
tests/e2e/multicard/2-cards/test_disaggregated_encoder.py
tests/e2e/multicard/2-cards/test_expert_parallel.py
tests/e2e/multicard/2-cards/test_external_launcher.py
tests/e2e/multicard/2-cards/test_full_graph_mode.py
tests/e2e/multicard/2-cards/test_ilama_lora_tp2.py
tests/e2e/multicard/2-cards/test_offline_inference_distributed.py
tests/e2e/multicard/2-cards/test_offline_weight_load.py
tests/e2e/multicard/2-cards/test_pipeline_parallel.py
tests/e2e/multicard/2-cards/test_prefix_caching.py
tests/e2e/multicard/2-cards/test_quantization.py
tests/e2e/multicard/2-cards/test_qwen3_moe.py
tests/e2e/multicard/2-cards/test_qwen3_moe_routing_replay.py
tests/e2e/multicard/2-cards/test_qwen3_performance.py
tests/e2e/multicard/2-cards/test_shared_expert_dp.py
tests/e2e/multicard/2-cards/test_single_request_aclgraph.py
tests/e2e/multicard/2-cards/test_sp_pass.py

Does this PR introduce any user-facing change?

How was this patch tested?

@github-actions
Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

@MrZ20 MrZ20 marked this pull request as ready for review February 13, 2026 08:03
@MrZ20 MrZ20 requested a review from wangxiyuan as a code owner February 13, 2026 08:03
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @MrZ20, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request initiates the conversion of the test/ directory to Ruff formatting, focusing on a specific batch of tests/e2e files. The changes primarily involve applying consistent code style, modernizing type hints, and refining error handling mechanisms within the affected test infrastructure. This effort aims to enhance code readability, maintainability, and adherence to modern Python best practices across the test suite.

Highlights

  • Ruff Configuration Update: Updated the pyproject.toml to expand the exclude list for Ruff, specifically adding several tests/e2e subdirectories. This indicates a phased approach to applying Ruff formatting across the test suite, with this PR focusing on a subset of files.
  • Code Formatting and Style Consistency: Applied extensive automatic code formatting across numerous Python test files. This includes consistent use of trailing commas in function calls and dictionary definitions, improved line breaking for readability, and adjusted spacing, aligning with Ruff's style guidelines.
  • Modernized Type Hinting: Modernized Python type hints in tests/e2e/conftest.py and tests/e2e/model_utils.py by replacing typing.Optional, typing.Union, and typing.Tuple with the more concise native | None and tuple[...] syntax, improving code clarity and leveraging newer Python features.
  • Refactored Error Handling: Refactored process termination error handling in tests/e2e/conftest.py to use contextlib.suppress(psutil.NoSuchProcess), making the code more robust and concise when dealing with potentially terminated child processes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pyproject.toml
    • Expanded Ruff's exclude list to defer linting for several tests/e2e subdirectories, indicating a staged rollout of Ruff formatting.
  • tests/e2e/310p/multicard/test_dense_model_multicard.py
    • Reformatted VllmRunner instantiation with consistent trailing commas and adjusted line breaks for improved readability.
  • tests/e2e/310p/multicard/test_moe_model_multicard.py
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
  • tests/e2e/310p/singlecard/test_dense_model_singlecard.py
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
  • tests/e2e/conftest.py
    • Updated type hints from typing.Optional, typing.Union, and typing.Tuple to native | None and tuple[...] syntax.
    • Removed unused torch_npu import from _check_npu_memory_worker.
    • Adjusted string formatting in print statements for consistency.
    • Replaced try...except psutil.NoSuchProcess blocks with contextlib.suppress for cleaner error handling.
    • Standardized environment variable key VLLM_WORKER_MULTIPROC_METHOD to use double quotes.
    • Reformatted various function arguments and dictionary definitions with consistent trailing commas and line breaks.
  • tests/e2e/model_utils.py
    • Updated Sequence import from typing to collections.abc.
    • Modernized type hints from Tuple[List[int], str] to tuple[list[int], str] and simplified Union types.
    • Adjusted f-string formatting in check_outputs_equal for better readability.
  • tests/e2e/models/conftest.py
    • Reformatted list comprehension for configs with improved line breaking.
  • tests/e2e/models/test_lm_eval_correctness.py
    • Reformatted dictionary definitions and f-strings for style consistency.
    • Simplified boolean logic for enable_expert_parallel in build_model_args.
  • tests/e2e/multicard/2-cards/spec_decode/test_spec_decode.py
    • Removed unused imports math, random, Any, Union, and LLM.
    • Reformatted function arguments and dictionary definitions with consistent trailing commas and line breaks.
  • tests/e2e/multicard/2-cards/test_aclgraph_capture_replay.py
    • Reordered imports for AscendDeviceType and get_ascend_device_type.
    • Reformatted patch.object calls and subprocess.run arguments.
    • Simplified boolean logic for enable_expert_parallel in _run_worker_process.
    • Adjusted f-string formatting and error messages for clarity.
  • tests/e2e/multicard/2-cards/test_data_parallel.py
    • Reformatted subprocess.run arguments for improved readability.
  • tests/e2e/multicard/2-cards/test_disaggregated_encoder.py
    • Added an empty line for spacing.
    • Reformatted long lists of arguments in vllm_server_args and proxy_args for better readability.
  • tests/e2e/multicard/2-cards/test_expert_parallel.py
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
  • tests/e2e/multicard/2-cards/test_external_launcher.py
    • Added an empty line for spacing.
    • Simplified path construction for script variable.
    • Reformatted subprocess.run arguments and cmd list for improved readability.
  • tests/e2e/multicard/2-cards/test_full_graph_mode.py
    • Standardized environment variable key HCCL_OP_EXPANSION_MODE to use double quotes.
    • Reformatted VllmRunner instantiations and list appends with consistent trailing commas and line breaks.
  • tests/e2e/multicard/2-cards/test_ilama_lora_tp2.py
    • Reformatted VllmRunner instantiation with consistent trailing commas and adjusted line breaks.
    • Simplified import statement for EXPECTED_LORA_OUTPUT, MODEL_PATH, do_sample.
  • tests/e2e/multicard/2-cards/test_offline_inference_distributed.py
    • Added empty lines for spacing.
    • Reformatted VllmRunner instantiations and SamplingParams with consistent trailing commas and line breaks.
    • Reformatted vllm_ds_w4a8_answers list and vllm_answer_list creation for style consistency.
  • tests/e2e/multicard/2-cards/test_offline_weight_load.py
    • Simplified path construction for script variable.
    • Reformatted subprocess.run arguments for improved readability.
  • tests/e2e/multicard/2-cards/test_pipeline_parallel.py
    • Reformatted VllmRunner instantiation with consistent trailing commas and adjusted line breaks.
  • tests/e2e/multicard/2-cards/test_prefix_caching.py
    • Added ruff: noqa: E501 comment to suppress line length warning for LONG_PROMPT.
    • Reformatted LONG_PROMPT and INPUT_PROMPTS for better readability.
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
  • tests/e2e/multicard/2-cards/test_quantization.py
    • Removed unused pytest import.
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
    • Standardized golden_results string literals to use double quotes.
  • tests/e2e/multicard/2-cards/test_qwen3_moe.py
    • Reformatted VllmRunner instantiations with consistent trailing commas and adjusted line breaks.
    • Standardized environment variable key HCCL_OP_EXPANSION_MODE to use double quotes.
    • Reformatted RemoteOpenAIServer and client.completions.create calls with consistent trailing commas and line breaks.
  • tests/e2e/multicard/2-cards/test_qwen3_performance.py
    • Reformatted RemoteOpenAIServer instantiation with consistent trailing commas and adjusted line breaks.
  • tests/e2e/multicard/2-cards/test_shared_expert_dp.py
    • Standardized environment variable key HCCL_OP_EXPANSION_MODE to use double quotes.
    • Reformatted VllmRunner instantiations and list appends with consistent trailing commas and line breaks.
  • tests/e2e/multicard/2-cards/test_single_request_aclgraph.py
    • Reformatted server_args lists and asyncio.wait_for call with consistent trailing commas and line breaks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
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 applies ruff formatting to a batch of test files, which is a good step towards code consistency. The changes are mostly stylistic, such as updating type hints to modern syntax and reformatting code blocks. However, I've identified a critical issue in tests/e2e/conftest.py where a necessary import was removed from a function that runs in a subprocess. This will likely lead to a runtime error. Please address this issue.

Comment thread tests/e2e/conftest.py
Comment on lines 93 to 96
# We can try to clean up memory in this subprocess, though it mostly affects this process.
# But if there are any lingering contexts in this process (unlikely for a fresh spawn), it helps.
gc.collect()
torch.npu.empty_cache()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The _check_npu_memory_worker function is executed in a separate process via multiprocessing.get_context("spawn"). A spawned process does not inherit the parent's imported modules. Therefore, torch_npu must be imported within this worker function to register the NPU backend with PyTorch.

The removal of import torch_npu will cause torch.npu to be unavailable in the subprocess, leading to an AttributeError at runtime when torch.npu.empty_cache() or torch.npu.mem_get_info() is called. This is a critical bug.

Please add the import back.

Suggested change
# We can try to clean up memory in this subprocess, though it mostly affects this process.
# But if there are any lingering contexts in this process (unlikely for a fresh spawn), it helps.
gc.collect()
torch.npu.empty_cache()
import torch_npu # type: ignore
# We can try to clean up memory in this subprocess, though it mostly affects this process.
# But if there are any lingering contexts in this process (unlikely for a fresh spawn), it helps.
gc.collect()
torch.npu.empty_cache()

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Signed-off-by: MrZ20 <2609716663@qq.com>
@wangxiyuan wangxiyuan merged commit 43df2cb into vllm-project:main Mar 10, 2026
36 checks passed
@MrZ20 MrZ20 deleted the lint-test-1 branch March 11, 2026 01:48
Nagisa125 pushed a commit to starmountain1997/vllm-ascend that referenced this pull request Mar 17, 2026
…lm-project#6738)

### What this PR does / why we need it?
**Scope of Changes**:
| File Path |
| :--- |
| `tests/e2e/310p/multicard/test_vl_model_multicard.py` |
| `tests/e2e/310p/singlecard/test_vl_model_singlecard.py` |
| `tests/e2e/310p/test_utils.py` |
| `tests/e2e/conftest.py` |
| `tests/e2e/model_utils.py` |
| `tests/e2e/models/conftest.py` |
| `tests/e2e/models/test_lm_eval_correctness.py` |
| `tests/e2e/multicard/2-cards/spec_decode/test_spec_decode.py` |
| `tests/e2e/multicard/2-cards/test_aclgraph_capture_replay.py` |
| `tests/e2e/multicard/2-cards/test_data_parallel.py` |
| `tests/e2e/multicard/2-cards/test_disaggregated_encoder.py` |
| `tests/e2e/multicard/2-cards/test_expert_parallel.py` |
| `tests/e2e/multicard/2-cards/test_external_launcher.py` |
| `tests/e2e/multicard/2-cards/test_full_graph_mode.py` |
| `tests/e2e/multicard/2-cards/test_ilama_lora_tp2.py` |
| `tests/e2e/multicard/2-cards/test_offline_inference_distributed.py` |
| `tests/e2e/multicard/2-cards/test_offline_weight_load.py` |
| `tests/e2e/multicard/2-cards/test_pipeline_parallel.py` |
| `tests/e2e/multicard/2-cards/test_prefix_caching.py` |
| `tests/e2e/multicard/2-cards/test_quantization.py` |
| `tests/e2e/multicard/2-cards/test_qwen3_moe.py` |
| `tests/e2e/multicard/2-cards/test_qwen3_moe_routing_replay.py` |
| `tests/e2e/multicard/2-cards/test_qwen3_performance.py` |
| `tests/e2e/multicard/2-cards/test_shared_expert_dp.py` |
| `tests/e2e/multicard/2-cards/test_single_request_aclgraph.py` |
| `tests/e2e/multicard/2-cards/test_sp_pass.py` |

### Does this PR introduce _any_ user-facing change?

### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@9562912

Signed-off-by: MrZ20 <2609716663@qq.com>
Co-authored-by: wangxiyuan <wangxiyuan1007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants