Run pytest tests without coverage reporting.
jobs:
test:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-pytest.yml@v1
with:
dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}| Input | Type | Required | Default | Description |
|---|---|---|---|---|
python-version |
string | No | '3.12' |
Python version to use |
working-directory |
string | No | '.' |
Working directory for tests |
dependencies-cache-key |
string | No | '' |
Cache key from dependency-manager job |
pytest-args |
string | No | '' |
Additional pytest arguments |
runs-on |
string | No | 'ubuntu-latest' |
Runner to use |
None
- Restore Cache: Restores dependencies if cache key provided
- Add to PATH: Adds
.venv/binto PATH for pytest access - Run pytest: Executes tests with optional custom arguments
- Default:
pytest -q(quiet mode) - With args:
pytest {custom-args}
- Default:
jobs:
dependencies:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-dependency-manager.yml@v1
test:
needs: dependencies
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-pytest.yml@v1
with:
dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}jobs:
test:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-pytest.yml@v1
with:
pytest-args: '-v --tb=short tests/unit/'jobs:
dependencies:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-dependency-manager.yml@v1
test:
needs: dependencies
strategy:
matrix:
test-dir: [tests/unit, tests/integration, tests/e2e]
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-pytest.yml@v1
with:
dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}
pytest-args: '${{ matrix.test-dir }}'jobs:
test:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-pytest.yml@v1pytest configuration in pyproject.toml:
[tool.pytest.ini_options]
minversion = "7.0"
addopts = "-ra -q --strict-markers"
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"slow: marks tests as slow",
"integration: marks tests as integration tests",
]Or separate pytest.ini:
[pytest]
minversion = 7.0
addopts = -ra -q --strict-markers
testpaths = tests
python_files = test_*.py *_test.py
markers =
slow: marks tests as slow
integration: marks tests as integration testsProblem: pytest: command not found
Cause: pytest not installed in dependencies.
Solution: Add pytest to dev dependencies:
# Poetry
poetry add --group dev pytest
# uv
uv add --dev pytest
# venv
echo "pytest>=7.0.0" >> requirements-dev.txtProblem: ModuleNotFoundError when running tests.
Cause: Project not installed or PYTHONPATH not set.
Solution: Ensure project is installed in development mode:
# Poetry (automatic with poetry install)
poetry install
# uv
uv sync
# venv with pyproject.toml
pip install -e .
# venv with setup.py
pip install -e .Problem: pytest exits with "no tests ran in X seconds"
Cause: Test discovery not finding test files.
Solution: Check test discovery settings:
[tool.pytest.ini_options]
# Ensure testpaths points to correct directory
testpaths = ["tests"]
# Check naming patterns match your test files
python_files = ["test_*.py", "*_test.py"]