Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/quantco/pytest-action
:octocat: GitHub Action to run pytest with GitHub Job Summaries support :snake: :rocket:
https://github.com/quantco/pytest-action
infrastructure
Last synced: about 2 months ago
JSON representation
:octocat: GitHub Action to run pytest with GitHub Job Summaries support :snake: :rocket:
- Host: GitHub
- URL: https://github.com/quantco/pytest-action
- Owner: Quantco
- Created: 2022-06-30T14:33:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-30T08:41:32.000Z (7 months ago)
- Last Synced: 2024-05-30T10:17:47.662Z (7 months ago)
- Topics: infrastructure
- Language: Python
- Homepage:
- Size: 178 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# GitHub Action for pytest
This GitHub Action allows you to run `pytest` and output [GitHub Job Summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/). For creating the job summaries, this action uses [`pytest-md`](https://github.com/hackebrot/pytest-md) and [`pytest-emoji`](https://github.com/hackebrot/pytest-emoji).
```yml
- name: Run pytest
uses: quantco/pytest-action@v2
with:
verbose: true
emoji: true
job-summary: true
custom-arguments: '-q'
click-to-expand: true
report-title: 'Test Report'
```You need to have Python as well as `pytest` installed in your pipeline before you can run this action. If `job-summary` is set to `true`, you also need to install `pytest-md`. If `emoji` is set to `true`, you need to install `pytest-emoji`.
When `job-summary` is set to `true`, the action will output a Job Summary.
![Example Job Summary](./.github/assets/summary-example-light.png#gh-light-mode-only)
![Example Job Summary](./.github/assets/summary-example-dark.png#gh-dark-mode-only)## Inputs
| parameter | description | required | default |
| --- | --- | --- | --- |
| job-summary | Print a GitHub job summary | `false` | true |
| verbose | Verbose output | `false` | true |
| emoji | Use emojis in the output | `false` | true |
| custom-arguments | Custom arguments to pass to pytest | `false` | |
| custom-pytest | Custom command to replace the `pytest` call. Can be a custom executable or something like `poetry run pytest` or `micromamba run -n myenv pytest`. | `false` | pytest |
| report-title | Title of the report | `false` | Test Report |
| click-to-expand | Add 'Click to expand' to the report | `false` | true |## Setting time zone
If you want to change the time zone of the job summary, you may want to use the [szenius/set-timezone](https://github.com/marketplace/actions/set-timezone) action:
```yml
- name: Set timezone
uses: szenius/set-timezone@ce9c440bc3af4f51b28d7ef7e5c47ee8f26c8dcb
with:
timezone: 'Europe/Berlin'
```## Activating `conda` environments
This action uses `bash -l {0}` as the shell to run `pytest` in,
i.e., the login shell that also sources your `.bash_profile`.
When using `bash` in GitHub Actions, it doesn't source your `.bash_profile` by default.
If you want to use a `conda` environment, you need to make sure to add it into your `.bash_profile` s.t.
the `conda` environment automatically gets activated.
[mamba-org/setup-micromamba](https://github.com/mamba-org/setup-micromamba)
does this automatically for you.```yml
- uses: mamba-org/setup-micromamba@v1
with:
environment-name: myenv
create-args: >-
python=3.11
pytest
numpy
pytest-md
pytest-emoji
# first checkout and then use the action because dependabot crashes when it sees private repositories
- name: Checkout quantco/pytest-action
uses: actions/checkout@v3
with:
repository: quantco/pytest-action
ref: v2
token: ${{ secrets.FQ_GH_TOKEN }}
path: .github/pytest-action
- name: Run unittests
uses: ./.github/pytest-action
```## Example Usage
```yml
name: Run Python testson: [push]
jobs:
build:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]steps:
- uses: szenius/set-timezone@ce9c440bc3af4f51b28d7ef7e5c47ee8f26c8dcb
with:
timezoneLinux: "Europe/Berlin"
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install pytest pytest-md pytest-emoji
# first checkout and then use the action because dependabot crashes when it sees private repositories
- name: Checkout quantco/pytest-action
uses: actions/checkout@v3
with:
repository: quantco/pytest-action
ref: v2
token: ${{ secrets.FQ_GH_TOKEN }}
path: .github/pytest-action
- name: Run unittests
uses: ./.github/pytest-action
with:
emoji: false
verbose: false
job-summary: true
```