{"id":27167261,"url":"https://github.com/lfreleng-actions/python-test-action","last_synced_at":"2026-02-26T08:17:53.107Z","repository":{"id":284962404,"uuid":"954829781","full_name":"lfreleng-actions/python-test-action","owner":"lfreleng-actions","description":"Tests a Python project and generates coverage reports","archived":false,"fork":false,"pushed_at":"2025-06-02T22:50:21.000Z","size":85,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T01:28:30.665Z","etag":null,"topics":["github-actions","pytest","python","test","testing","tests"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lfreleng-actions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-25T17:19:54.000Z","updated_at":"2025-06-02T22:50:33.000Z","dependencies_parsed_at":"2025-05-26T13:43:41.816Z","dependency_job_id":"7d307a0f-5ae1-4f5f-9b8a-2ae0519d06fa","html_url":"https://github.com/lfreleng-actions/python-test-action","commit_stats":null,"previous_names":["lfreleng-actions/python-test-action"],"tags_count":8,"template":false,"template_full_name":"lfreleng-actions/actions-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfreleng-actions%2Fpython-test-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfreleng-actions%2Fpython-test-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfreleng-actions%2Fpython-test-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfreleng-actions%2Fpython-test-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfreleng-actions","download_url":"https://codeload.github.com/lfreleng-actions/python-test-action/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfreleng-actions%2Fpython-test-action/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258457354,"owners_count":22704404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-actions","pytest","python","test","testing","tests"],"created_at":"2025-04-09T04:51:27.566Z","updated_at":"2026-02-26T08:17:53.102Z","avatar_url":"https://github.com/lfreleng-actions.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n# SPDX-License-Identifier: Apache-2.0\n# SPDX-FileCopyrightText: 2025 The Linux Foundation\n--\u003e\n\n# 🐍 Test Python Project\n\nTests a Python project and generates coverage reports.\n\nThere are two ways for tests to run:\n\n- Using pytest and pytest-cov to run tests and generate coverage reports\n- Using tox when provided with a suitable configuration file\n\n## python-test-action\n\n## Usage Example\n\nThe example below demonstrates an implementation as a matrix job:\n\n\u003c!-- markdownlint-disable MD046 --\u003e\n\n```yaml\n  python-tests:\n    name: \"Python Test\"\n    runs-on: \"ubuntu-24.04\"\n    needs:\n      - python-build\n    # Matrix job\n    strategy:\n      fail-fast: false\n      matrix: ${{ fromJson(needs.python-build.outputs.matrix_json) }}\n    permissions:\n      contents: read\n    steps:\n      - name: \"Test Python project\"\n        uses: lfreleng-actions/python-test-action@main\n        with:\n          python_version: ${{ matrix.python-version }}\n          report_artefact: true\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n```\n\nNote: build your project before invoking tests (not shown above)\n\n\u003c!-- markdownlint-enable MD046 --\u003e\n\n## Inputs\n\n\u003c!-- markdownlint-disable MD013 --\u003e\n\n| Variable Name   | Required | Default       | Description                                                               |\n| --------------- | -------- | ------------- | ------------------------------------------------------------------------- |\n| python_version  | True     |               | Python version used to run tests                                          |\n| editable        | False    | False         | Install Python package in editable mode                                   |\n| permit_fail     | False    | False         | Continue even when one or more tests fail                                 |\n| report_artefact | False    | True          | Uploads test/coverage report bundle as artefact                           |\n| artefact_name   | False    |               | Custom name for uploaded artefact                                         |\n| path_prefix     | False    | .             | Directory location containing Python project code                         |\n| tests_path      | False    | auto-detect   | Relative path to the folder containing tests (detects: `test` or `tests`) |\n| tox_tests       | False    | False         | Uses tox to perform Python tests (requires tox.ini)                       |\n| tox_envs        | False    | \"lint tests\"  | Space separated list of tox environment names to run                      |\n| github_token    | False    |               | GitHub token for API access during tests                                  |\n| pytest_args     | False    |               | Custom pytest arguments (e.g., -n0, -v, --tb=short)                       |\n\n\u003c!-- markdownlint-enable MD013 --\u003e\n\nSet artefact_name to avoid artefact naming conflicts when matrix jobs\nproduce identical filenames, which can cause workflow failures when\nattempting to upload them to a workflow run.\n\n## Editable Installation Mode\n\nBy default, the action installs the Python package in **standard (non-editable)**\nmode. This is the recommended approach for CI/CD testing as it:\n\n- Tests the package as users will actually install it\n- Avoids rebuild issues with complex build systems (e.g., meson-python)\n- Is faster and more reliable in CI environments\n\nSet `editable: true` when you specifically need editable installs for\ndevelopment workflows or when testing local code changes.\n\n### Example with Editable Mode\n\n```yaml\n- name: \"Test Python project with editable install\"\n  uses: lfreleng-actions/python-test-action@main\n  with:\n    python_version: \"3.12\"\n    editable: true\n```\n\n## Coverage Reports\n\nThe embedded pytest behaviour will create HTML coverage reports as ZIP file\nbundles. Set REPORT_ARTEFACT true to also upload them to GitHub as artefacts.\n\n## GitHub Token Support\n\nThe action accepts an optional `github_token` input parameter that makes the\nGitHub token available to your tests as the `GITHUB_TOKEN` environment variable.\nThis is useful for tests that need to interact with GitHub APIs or access\nprivate repositories without encountering rate limits.\n\n### Example with GitHub Token\n\n```yaml\n- name: \"Test Python project with GitHub API access\"\n  uses: lfreleng-actions/python-test-action@main\n  with:\n    python_version: \"3.12\"\n    github_token: ${{ secrets.GITHUB_TOKEN }}\n    report_artefact: true\n```\n\n## Custom Pytest Arguments\n\nThe action supports passing custom arguments to pytest through the\n`pytest_args` input. This is useful for controlling test execution behavior,\nsuch as disabling parallel execution or adjusting output verbosity.\n\n**Security Note:** The action validates and sanitizes all pytest arguments to\nprevent command injection. You must use safe characters and pytest-compatible flags.\n\n### Example with Custom Pytest Arguments\n\n```yaml\n- name: \"Test Python project with serial execution\"\n  uses: lfreleng-actions/python-test-action@main\n  with:\n    python_version: \"3.10\"\n    pytest_args: \"-n0\"  # Disable parallel execution\n    report_artefact: true\n```\n\n```yaml\n- name: \"Test Python project with custom arguments\"\n  uses: lfreleng-actions/python-test-action@main\n  with:\n    python_version: \"3.10\"\n    pytest_args: \"-v -x --tb=short\"  # Three arguments combined\n    report_artefact: true\n```\n\n### Common pytest_args Examples\n\n- `-n0` - Disable parallel execution (run tests serially)\n- `-v` - Verbose output\n- `-vv` - Extra verbose output\n- `--tb=short` - Shorter traceback format\n- `-k test_name` - Run tests matching the expression\n- `-x` - Stop after first failure\n- `--maxfail=2` - Stop after 2 failures\n\n**Note:** The action accepts pytest arguments that start with `-` or `--`,\nor valid pytest expressions/paths. The action validates arguments to ensure they\ncontain safe characters (alphanumeric, space, `-`, `=`, `,`, `.`, `/`, `:`, `_`).\nUse space-separated strings to pass arguments (e.g., `\"-n0 -v\"`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfreleng-actions%2Fpython-test-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfreleng-actions%2Fpython-test-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfreleng-actions%2Fpython-test-action/lists"}