Skip to content

Conversation

GregoryComer
Copy link
Member

@GregoryComer GregoryComer commented Sep 22, 2025

Refactor the backend test suites to use pytest. This includes the following changes:

  • Define pytest markers for each backend and test flow (recipe). This allows for easy filter, such as by running pytest some/path/... -m backend_xnnpack.
  • Use a parameterized pytest fixture to handle test generation / expansion for each test flow.
  • Switch to using the pytest-json-report plugin for reporting. Update the markdown generation script to take json.
  • Shim the existing unittest-based logic for op tests.
    • I've updated add.py to show what they should look like long-term. I've also just updated the model tests, since there aren't as many. I'll update the remaining op tests later in this stack, though this is purely to clean up the code. The shimming logic makes them work properly with pytest in this PR.
  • Update the backend test CI to use pytest.

This also has the benefit of making the jobs much faster by leveraging parallel execution. I've also added a repro command to the markdown summary.

[ghstack-poisoned]
@GregoryComer
Copy link
Member Author

GregoryComer commented Sep 22, 2025

Stack from ghstack (oldest at bottom):

Copy link

pytorch-bot bot commented Sep 22, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/14456

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 5 New Failures, 2 Cancelled Jobs, 2 Unrelated Failures

As of commit 92eac20 with merge base bef9555 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

GregoryComer added a commit that referenced this pull request Sep 22, 2025
ghstack-source-id: 4b9e26f
ghstack-comment-id: 3316692916
Pull-Request: #14456
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 22, 2025
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: ebc1b98
ghstack-comment-id: 3316692916
Pull-Request: #14456
@GregoryComer GregoryComer added ciflow/nightly release notes: none Do not include this in the release notes labels Sep 23, 2025
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: b1148f2
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: 97bf0ed
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: 9b49e55
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: dc6592c
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: edcfbe4
ghstack-comment-id: 3316692916
Pull-Request: #14456
@GregoryComer GregoryComer marked this pull request as ready for review September 23, 2025 18:27
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 23, 2025
ghstack-source-id: 7f812d4
ghstack-comment-id: 3316692916
Pull-Request: #14456
return _ALL_TEST_FLOWS


def dtype_to_str(dtype: torch.dtype) -> str:
Copy link
Member Author

Choose a reason for hiding this comment

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

This utility function is used for generating the display name for parameterized tests.


test_kwargs = copy.copy(params) or {}
test_kwargs["flow"] = flow
def wrap_test(original_func, test_type):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is shim code to make the existing op tests work with the new pytest setup. It will be removed once I update all of the op tests. Note that this is not a functional change, just code cleanup. It's using the proper pytest fixtures and parameterization with this PR, just through this shim instead of directly.


EXIT_CODE=0
python -m executorch.backends.test.suite.runner $SUITE --flow $FLOW --report "$REPORT_FILE" || EXIT_CODE=$?
pytest -c /dev/nul -n auto backends/test/suite/$SUITE/ -m flow_$FLOW --json-report --json-report-file="$REPORT_FILE" || EXIT_CODE=$?
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI we don't exactly love pytest when not working in OSS.

Copy link
Member Author

@GregoryComer GregoryComer Sep 24, 2025

Choose a reason for hiding this comment

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

Do you have concerns with using pytest? Or suggested changes?

[ghstack-poisoned]
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: 4366615
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: 04ee13c
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: 20cc9ad
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: 352a6ac
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: e1bf77d
ghstack-comment-id: 3316692916
Pull-Request: #14456
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: e1bf77d
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 25, 2025
ghstack-source-id: 76437b0
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 26, 2025
ghstack-source-id: 5e2bc77
ghstack-comment-id: 3316692916
Pull-Request: #14456
[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Sep 26, 2025
ghstack-source-id: 9172228
ghstack-comment-id: 3316692916
Pull-Request: #14456
@GregoryComer GregoryComer marked this pull request as ready for review September 26, 2025 02:17
Copy link
Contributor

@digantdesai digantdesai left a comment

Choose a reason for hiding this comment

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

Thanks!



@pytest.hookimpl(optionalhook=True)
def pytest_json_runtest_metadata(item, call):
Copy link
Contributor

Choose a reason for hiding this comment

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

For pytest-json-report I assume?

${CONDA_RUN} --no-capture-output pip install awscli==1.37.21
source .ci/scripts/test_backend_macos.sh "${{ matrix.suite }}" "${{ matrix.flow }}" "${RUNNER_ARTIFACT_DIR}"
source .ci/scripts/test_backend.sh "${{ matrix.suite }}" "${{ matrix.flow }}" "${RUNNER_ARTIFACT_DIR}"
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@GregoryComer GregoryComer merged commit d09dd79 into main Sep 29, 2025
336 of 346 checks passed
@GregoryComer GregoryComer deleted the gh/GregoryComer/165/head branch September 29, 2025 18:04
@GregoryComer
Copy link
Member Author

@pytorchbot cherry-pick --onto release/1.0 -c testci

Copy link

pytorch-bot bot commented Sep 29, 2025

❌ 🤖 pytorchbot command failed:

@pytorchbot cherry-pick: error: argument -c/--classification: invalid choice: 'testci' (choose from 'regression', 'critical', 'fixnewfeature', 'docs', 'release')

usage: @pytorchbot cherry-pick --onto ONTO [--fixes FIXES] -c
                               {regression,critical,fixnewfeature,docs,release}

Try @pytorchbot --help for more info.

@GregoryComer
Copy link
Member Author

@pytorchbot cherry-pick --onto release/1.0 -c fixnewfeature

pytorchbot pushed a commit that referenced this pull request Sep 29, 2025
Refactor the backend test suites to use pytest. This includes the
following changes:
* Define pytest markers for each backend and test flow (recipe). This
allows for easy filter, such as by running `pytest some/path/... -m
backend_xnnpack`.
* Use a parameterized pytest fixture to handle test generation /
expansion for each test flow.
* Switch to using the pytest-json-report plugin for reporting. Update
the markdown generation script to take json.
* Shim the existing unittest-based logic for op tests.
* I've updated add.py to show what they should look like long-term. I've
also just updated the model tests, since there aren't as many. I'll
update the remaining op tests later in this stack, though this is purely
to clean up the code. The shimming logic makes them work properly with
pytest in this PR.
 * Update the backend test CI to use pytest.

This also has the benefit of making the jobs much faster by leveraging
parallel execution. I've also added a repro command to the markdown
summary.

(cherry picked from commit d09dd79)
@pytorchbot
Copy link
Collaborator

Cherry picking #14456

The cherry pick PR is at #14661 and it is recommended to link a fixnewfeature cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/nightly CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants