Skip to content

Pytest linux

Pytest linux #2324

Workflow file for this run

name: Pytest linux
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "15 7 * * *"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
PYTHONPATH: ${{ github.workspace }}/src
SENZING_TOOLS_DATABASE_URL: sqlite3://na:na@nowhere/tmp/sqlite/G2C.db
permissions: {}
jobs:
sdk-versions:
runs-on: ubuntu-latest
outputs:
senzingsdk-versions: ${{ steps.cfg.outputs.senzingsdk-versions }}
steps:
- id: cfg
uses: senzing-factory/build-resources/sdk-versions@v4
pytest-linux:
name: "Pytest with Senzing: ${{ matrix.senzingsdk-version }}; OS: ${{ matrix.os }}; Python ${{ matrix.python-version }}"
needs: sdk-versions
permissions:
contents: read
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]
senzingsdk-version: ${{ fromJSON(needs.sdk-versions.outputs.senzingsdk-versions) }}
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m venv ./venv
source ./venv/bin/activate
echo "PATH=${PATH}" >> "${GITHUB_ENV}"
python -m pip install --upgrade pip
python -m pip install --group all .
- if: matrix.python-version == '3.10'
name: Install python libraries for python 3.10
run: |
source ./venv/bin/activate
python -m pip install typing_extensions
- name: Install Senzing SDK
uses: senzing-factory/github-action-install-senzing-sdk@v4
with:
senzingsdk-version: ${{ matrix.senzingsdk-version }}
- name: Set environment variables
run: |
SENZING_PATH="/opt/senzing"
{
echo "SENZING_PATH=${SENZING_PATH}"
echo "LD_LIBRARY_PATH=${SENZING_PATH}/er/lib"
} >> "$GITHUB_ENV"
- name: Copy /etc files
run: |
sudo mkdir -p /etc/opt/senzing
sudo cp testdata/senzing-license/g2.lic /etc/opt/senzing/g2.lic
- name: Copy test database files
run: |
mkdir -p /tmp/sqlite
cp testdata/sqlite/G2C.db /tmp/sqlite/
- name: Enable core dumps
uses: senzing-factory/github-action-core-dumps@v1
with:
enable-core-dumps: "true"
- name: Run pytest
run: |
source ./venv/bin/activate
ulimit -c unlimited
pytest tests/ --verbose --capture=no --cov=src --cov-append
- if: always()
name: Analyze core dumps
uses: senzing-factory/github-action-core-dumps@v1
with:
analyze-core-dumps: "true"
core-file-suffix: ${{ matrix.senzingsdk-version }}-${{ matrix.python-version }}
# Use pytest to check examples, there are no "test" classes/functions, pytest imports
# the .py files. If there is a Python error in the examples, an exit code of 1
# is returned. If there are no Python errors but pytest didn't think it found any
# tests an exit code of 5 is returned, this is a pass but need to capture it and
# return 0 - https://docs.pytest.org/en/stable/reference/exit-codes.html
- name: Run pytest on examples
run: |
source ./venv/bin/activate
set +e
pytest \
examples/misc/ \
examples/extras/ \
examples/szabstractfactory/ \
examples/szconfig/ \
examples/szconfigmanager/ \
examples/szdiagnostic/ \
examples/szengine/ \
examples/szproduct/ \
--capture=no \
-o python_files=*.py \
--verbose
pytest_exit_code="$?"
set -e
if [ "$pytest_exit_code" -eq 5 ]; then
echo -e "\nExit code from pytest was $pytest_exit_code, this is expected testing the examples if there were no Python errors\n"
exit 0
else
exit "$pytest_exit_code"
fi
- name: Rename coverage file
env:
COVERAGE_FILE: "coverage.${{ matrix.python-version }}-${{ matrix.senzingsdk-version }}"
run: |
mv .coverage "$COVERAGE_FILE"
- name: Store coverage file
uses: actions/upload-artifact@v7
with:
name: "coverage-${{ matrix.python-version }}-${{ matrix.senzingsdk-version }}"
path: "coverage.${{ matrix.python-version }}-${{ matrix.senzingsdk-version }}"
coverage:
if: github.event_name == 'pull_request'
name: Coverage
needs: pytest-linux
permissions:
pull-requests: write
contents: write
uses: senzing-factory/build-resources/.github/workflows/python-coverage-comment.yaml@v4
slack-notification:
needs: [pytest-linux]
if: ${{ always() && contains(fromJSON('["failure", "cancelled"]'), needs.pytest-linux.result ) && (github.ref_name == github.event.repository.default_branch || github.event_name == 'schedule') }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
uses: senzing-factory/build-resources/.github/workflows/build-failure-slack-notification.yaml@v4
with:
job-status: ${{ needs.pytest-linux.result }}