pySPM icon indicating copy to clipboard operation
pySPM copied to clipboard

Improve test CI using pytest

Open ns-rse opened this issue 9 months ago • 2 comments

I noticed that the popular pytest package is not a dependency. Not clear how tests are run, and there is no Continuous Integration that run tests on pulls.

If an optional dependency on pytest were included a workflow similar to the following could be included (.github/workflows/tests.yaml)

.github/workflows/tests.yaml

name: Tests (pytest)

on:
  pull_request:
    types:
      - opened
      - ready_for_review
      - reopened
      - synchronize
    paths:
      - "**.csv"
      - "**.npy"
      - "**.out"
      - "**.pkl"
      - "**.png"
      - "**.py"
      - "**.toml"
      - "**.yaml"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Ex1 (${{ matrix.python-version }}, ${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ["ubuntu-latest", "macos-latest", "windows-latest"]
        python-version: ["3.10", "3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Upgrade pip and install test dependencies
        run: |
          pip install --upgrade virtualenv
          pip install --upgrade pip setuptools
          pip show pip setuptools
          virtualenv --upgrade-embed-wheels
          pip install -e .[tests]
      - name: Test with pytest
        run: |
          pytest --cov=pySPM --mpl -x
      - name: Determine coverage
        run: |
          coverage xml
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5

      - name: Setup tmate session
        if: ${{ failure() }}
        uses: mxschmitt/action-tmate@v3
        timeout-minutes: 5

pyproject.toml

Addition to pyproject.toml would be something like...

[project.optional-dependencies]
tests = [
  "pytest",
  "pytest-cov",
  "pytest-github-actions-annotate-failures",
]

ns-rse avatar May 09 '25 10:05 ns-rse

Hi ns-rse. You seem quite involved in the project where I lack the time and I'm not a user of my own library anymore. You seem to have quite good ideas. Should I add you as dev to the project?

scholi avatar May 23 '25 17:05 scholi

Hi @scholi

I work on TopoStats and AFMReader, the later depends on pySPM for loading files. I don't actually do any work with AFM images, I'm a Research Software Engineer who works with those who do.

I see you've already put a tests.yaml in place along with a workflow for publishing (and you've got the publishing working to TestPyPI 🎉 ).

I'm fairly busy with some other things but more than happy to help with pySPM and have accepted the invitation to collaborate.

Cheers,

@ns-rse

ns-rse avatar May 28 '25 09:05 ns-rse