-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[hotfix] Update get_pytest_timeout to prioritize marker retrieval with fallback logic #6307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Venky Ganesh <[email protected]>
WalkthroughThe function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
/bot run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
# Check pytest markers first (ensures "TIMEOUT" in l0_*.yml etc. is respected) | ||
try: | ||
import pytest | ||
marks = None | ||
try: | ||
current_item = pytest.current_test | ||
if hasattr(current_item, 'iter_markers'): | ||
marks = list(current_item.iter_markers('timeout')) | ||
except (AttributeError, NameError): | ||
pass | ||
|
||
if marks and len(marks) > 0: | ||
timeout_mark = marks[0] | ||
timeout_pytest = timeout_mark.args[0] if timeout_mark.args else None | ||
if timeout_pytest and isinstance(timeout_pytest, (int, float)): | ||
return timeout_pytest | ||
|
||
except (ImportError, Exception): | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Fix incorrect pytest API usage.
The code attempts to use pytest.current_test
which doesn't exist in pytest's API. This will always raise an AttributeError
and fall through to the command-line parsing logic.
The correct approaches to access the current test item in pytest are:
- Using pytest's internal API (if available in the execution context):
- try:
- current_item = pytest.current_test
- if hasattr(current_item, 'iter_markers'):
- marks = list(current_item.iter_markers('timeout'))
- except (AttributeError, NameError):
- pass
+ try:
+ # Access current test item through pytest's internal state
+ import _pytest.main
+ if hasattr(_pytest.main, '_current_item'):
+ current_item = _pytest.main._current_item
+ if hasattr(current_item, 'iter_markers'):
+ marks = list(current_item.iter_markers('timeout'))
+ except (AttributeError, NameError):
+ pass
- Alternative approach using pytest's config (more reliable):
+ try:
+ # Try to get timeout from pytest configuration
+ config = pytest.config if hasattr(pytest, 'config') else None
+ if config and hasattr(config, 'getoption'):
+ pytest_timeout = config.getoption('--timeout', default=None)
+ if pytest_timeout and isinstance(pytest_timeout, (int, float)):
+ return pytest_timeout
+ except (AttributeError, NameError):
+ pass
Let me verify the correct pytest API for accessing current test context:
🏁 Script executed:
#!/bin/bash
# Check pytest source code for current test access patterns
rg -A 10 -B 5 "current.*test|test.*current" --type py | head -50
Length of output: 4706
Invalid pytest API usage in get_pytest_timeout
The code on lines 336–355 calls pytest.current_test
, which doesn’t exist in pytest’s public API. Consequently, marker-based timeouts never get applied and the block is effectively dead.
To address this:
- Remove or disable the entire
pytest.current_test
block. - If you really need to support pytest markers, you must run under pytest with a plugin or fixture and then pass the timeout into your harness. For example:
- Use the pytest-timeout plugin and read its
--timeout
option via a fixture (pytestconfig.getoption("timeout")
). - Or define a custom hook/fixture that extracts the marker value and exposes it to your integration code.
- Use the pytest-timeout plugin and read its
- Otherwise, read the timeout from an environment variable or a command-line argument in your integration runner.
Suggested diff to remove the invalid block:
- # Check pytest markers first (ensures "TIMEOUT" in l0_*.yml etc. is respected)
- try:
- import pytest
- marks = None
- try:
- current_item = pytest.current_test
- if hasattr(current_item, 'iter_markers'):
- marks = list(current_item.iter_markers('timeout'))
- except (AttributeError, NameError):
- pass
-
- if marks and len(marks) > 0:
- timeout_mark = marks[0]
- timeout_pytest = timeout_mark.args[0] if timeout_mark.args else None
- if timeout_pytest and isinstance(timeout_pytest, (int, float)):
- return timeout_pytest
-
- except (ImportError, Exception):
- pass
Replace with a mechanism that actually runs under pytest and can access markers (e.g., via pytest fixtures or plugins), or rely on environment/CLI inputs.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# Check pytest markers first (ensures "TIMEOUT" in l0_*.yml etc. is respected) | |
try: | |
import pytest | |
marks = None | |
try: | |
current_item = pytest.current_test | |
if hasattr(current_item, 'iter_markers'): | |
marks = list(current_item.iter_markers('timeout')) | |
except (AttributeError, NameError): | |
pass | |
if marks and len(marks) > 0: | |
timeout_mark = marks[0] | |
timeout_pytest = timeout_mark.args[0] if timeout_mark.args else None | |
if timeout_pytest and isinstance(timeout_pytest, (int, float)): | |
return timeout_pytest | |
except (ImportError, Exception): | |
pass |
🤖 Prompt for AI Agents
In tests/integration/defs/trt_test_alternative.py around lines 336 to 355, the
code incorrectly uses pytest.current_test, which is not part of pytest's public
API, causing marker-based timeouts to never apply. Remove the entire block that
tries to access pytest.current_test and instead implement timeout retrieval by
either using pytest-timeout plugin with a fixture to get the timeout option or
by reading the timeout value from an environment variable or command-line
argument in your test harness.
PR_Github #12743 [ run ] triggered by Bot |
PR_Github #12743 [ run ] completed with state |
closing this as no longer required. |
Summary by CodeRabbit
New Features
Bug Fixes
Fixes the CI timeout failures due to #5942
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...
Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]
to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]
Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id
(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test
(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast
(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test
(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"
(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"
(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"
(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test
(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test
(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test
(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge
(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"
(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log
(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug
(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-list
parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.md
and the
scripts/test_to_stage_mapping.py
helper.kill
kill
Kill all running builds associated with pull request.
skip
skip --comment COMMENT
Skip testing for latest commit on pull request.
--comment "Reason for skipping build/test"
is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipeline
Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.