-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[CI ][Misc] Add timeout check for custom op CI and optimize test parameters #8755
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,43 @@ | |
| from datetime import datetime | ||
| import pytest | ||
|
|
||
| DURATION_THRESHOLD = 120 | ||
| SLOW_COUNT_LIMIT = 5 | ||
|
|
||
|
|
||
| _per_file_slow_cases = {} | ||
| _current_file = None | ||
|
|
||
|
|
||
| def pytest_runtest_setup(item): | ||
| item.start_time = time.time() | ||
|
|
||
|
|
||
| def pytest_runtest_teardown(item, nextitem): | ||
| global _current_file | ||
|
|
||
| file_path = item.fspath | ||
| duration = time.time() - item.start_time | ||
|
|
||
|
|
||
| if file_path not in _per_file_slow_cases: | ||
| _per_file_slow_cases[file_path] = 0 | ||
|
|
||
| if duration > DURATION_THRESHOLD: | ||
| _per_file_slow_cases[file_path] += 1 | ||
| cnt = _per_file_slow_cases[file_path] | ||
| print(f" Detected that the test case took too long, ({cnt}/{SLOW_COUNT_LIMIT}):{duration:.2f}s") | ||
|
|
||
| if cnt >= SLOW_COUNT_LIMIT: | ||
| print(f"\n The number of timeout test cases {file_path} ≥{SLOW_COUNT_LIMIT}\n") | ||
| _current_file = file_path | ||
|
|
||
|
|
||
| def pytest_runtest_call(item): | ||
| if _current_file == item.fspath: | ||
| print(f"CASE SKIP:{item.nodeid}") | ||
| pytest.skip(f"The use case takes too long.") | ||
|
Comment on lines
+9
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation uses a single global variable I suggest using the _per_file_slow_cases = {}
def pytest_runtest_setup(item):
item.start_time = time.time()
def pytest_runtest_teardown(item, nextitem):
file_path = item.fspath
duration = time.time() - item.start_time
if duration > DURATION_THRESHOLD:
_per_file_slow_cases[file_path] = _per_file_slow_cases.get(file_path, 0) + 1
cnt = _per_file_slow_cases[file_path]
print(f" Detected that the test case took too long, ({cnt}/{SLOW_COUNT_LIMIT}):{duration:.2f}s")
if cnt >= SLOW_COUNT_LIMIT:
print(f"\n The number of timeout test cases {file_path} ≥{SLOW_COUNT_LIMIT}\n")
def pytest_runtest_call(item):
if _per_file_slow_cases.get(item.fspath, 0) >= SLOW_COUNT_LIMIT:
print(f"CASE SKIP:{item.nodeid}")
pytest.skip("The use case takes too long.") |
||
|
|
||
|
|
||
| @pytest.hookimpl(tryfirst=True, hookwrapper=True) | ||
| def pytest_runtest_makereport(item, call): | ||
|
|
||
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.
The Pull Request title and summary do not adhere to the repository's style guide regarding format and required sections.
Suggested PR Title:
Suggested PR Summary:
References