When you run pytest in Github Actions then it'll run just fine but without any color.
Wouldn't it be nice to be able to see the same colors that you'd have in the terminal locally though? As luck would have it, you can configure this with a PYTEST_ADDOPTS
environment variable. See the example below.
name: Build and Test
on:
push:
jobs:
unittest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache-dependency-path: |
requirements.txt
dev-requirements.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .
- name: Run pytest
if: always()
env:
PYTEST_ADDOPTS: "--color=yes"
run: |
pytest tests
By configuring PYTEST_ADDOPTS: "--color=yes"
in the env
key you now get pretty colored output again.
Back to main.