fix(ci): Execute newly added or modified scheduled_only tests in pre-submits#4339
fix(ci): Execute newly added or modified scheduled_only tests in pre-submits#4339mesakhcienet wants to merge 1 commit into
scheduled_only tests in pre-submits#4339Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
81f5793 to
9e07cb9
Compare
| return found | ||
|
|
||
|
|
||
| def get_changed_tests(base_ref=None): |
There was a problem hiding this comment.
Do we want to detect both newly added tests and the modified tests, or just new tests? @shralex
There was a problem hiding this comment.
detecting modified tests sounds great
| changed_tests = get_changed_tests() # set[(file_path, test_name)] | ||
| if changed_tests: | ||
| for item in items: | ||
| item_file = item.nodeid.split("::", 1)[0] |
There was a problem hiding this comment.
item_file = os.path.abspath(item.nodeid.split("::", 1)[0])
There was a problem hiding this comment.
Kept it relative (reasoning in the newly_added_detection.py:185 / :191). nodeid is rootdir-relative but abspath is CWD-relative, so from a subdir it doubles the path and the match breaks. pytest.ini pins rootdir = repo root, so relative-vs-relative is already exact.
| except OSError: | ||
| continue | ||
| for name in touched_test_names(source, touched_lines): | ||
| changed.add((path, name)) |
There was a problem hiding this comment.
Thanks for the suggestion
I tried it but ended up keeping the repo-relative path, because abspath turned out to break the match. It resolves against the current working directory, while the conftest side (item.nodeid) is relative to the pytest rootdir. When those differ they diverge: collecting from tests/unit/ turns os.path.abspath(nodeid) into .../tests/unit/tests/unit/..._test.py, so the tuple no longer matches.
Since pytest.ini fixes rootdir = repo root = git toplevel, the git diff paths and the nodeid paths are already the same string, so the current relative compare is exact and CWD-independent. abspath would also pull in a repo_root lookup that isn't available on the maxtext_installed:true /deps runner.
I verified this empirically, but happy to revisit if there's a case where the paths don't line up, or you want us to strictly implement , thanks!
|
Thanks for the detailed review, @shralex @xibinliu — pushed an update addressing the feedback. summary of what changed: Applied as suggested
Adjusted with a small deviation (details in the threads)
Verification
Feel free to suggest changes. Thank you! |
14d996d to
71b8779
Compare
Description
This change makes the pre-submit execute the
scheduled_onlytests that a PR introduces or modifies, so each is verified at least once before merge, while unrelatedscheduled_onlytests remain nightly-only (unchanged).How it works
tests/conftest.pycomputes the set of tests a PR adds or modifies — viagit diff --unified=0 origin/<base>...HEAD— and dynamically applies a newnewly_addedmarker to the matching collected tests.<marker> and not scheduled_onlyto<marker> and (not scheduled_only or newly_added). Scheduled (nightly) runs are untouched and continue to run everything.Detection details / robustness
tests/utils/newly_added_detection.py(parse_changed_testsis pure;get_changed_testswraps git). Keeping it out ofconftest.pylets it be tested without importing absl/pytest/jax.(file_path, test_name)— so identically named tests in different files (e.g.test_basic_callappears in 6 files) do not cross-contaminate and pull unrelatedscheduled_onlytests into pre-submit..gitattributessets*.py diff=pythonsogit diffhunk headers expose the enclosingdef test_*for edits inside class methods (the suite is overwhelmingly class-based). This enables detection of modified tests, not just brand-new ones.fetch-depth: 0so the three-dotorigin/main...HEADdiff has a reachable merge-base (otherwise the shallow clone forces a less precise fallback).GITHUB_BASE_REF(thenmain), so PRs targeting a non-mainbranch are handled.Files changed
tests/conftest.pynewly_added(file-qualified match)tests/utils/newly_added_detection.py(new)tests/unit/newly_added_detection_test.py(new).github/workflows/run_tests_against_package.ymlfetch-depth: 0.github/workflows/run_pathways_tests.yml.gitattributes(new)*.py diff=pythonpytest.ininewly_addedmarkerShortcomings / future work
maxtext_installed=true(the runner doescd /deps, which is not a git work tree). Not on the current PR pre-submit path, but worth noting.run_pathways_tests.ymlchecks out via a hardcodedgit clone https://github.com/google/maxtext.git, which does not resolve fork build SHAs (pre-existing, out of scope here).Tests
New unit tests in
tests/unit/newly_added_detection_test.py(markedcpu_only) cover the diff parser across: new top-level function, new class method, modified method detected via the hunk header, cross-file name-collision isolation, non-test /src/changes ignored, and multi-file diffs.All commands run locally against the repo
.venv(Python 3.12).1. Unit tests
2. Lint gate (same hooks as
code_quality.yml)3. End-to-end through the real
conftest.py— a temporaryscheduled_onlyprobe test committed on the branch, collected through the actualtests/conftest.py:This confirms the full chain:
git diff→ file-qualified parse →newly_addedmarker → survives-mselection → thescheduled_onlytest runs. The.gitattributeschange was separately verified to makegit diff --unified=0emit@@ ... @@ def test_column(...)headers for edits inside class methods (instead of the enclosingclass ...line).4. CI: the two modified workflows exercise this change on the actual TPU / GPU / CPU and Pathways pre-submit runners in this PR.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.