Skip to content
Open
49 changes: 38 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ jobs:
defaults:
run:
shell: bash -l {0}
env:
COVERAGE_FILE: ${{ github.workspace }}/.coverage@python=${{ matrix.python-version }},biopython=${{ matrix.biopython-version || 'latest' }}
COVERAGE_RCFILE: ${{ github.workspace }}/.coveragerc
steps:
- uses: actions/checkout@v4

Expand All @@ -73,7 +70,7 @@ jobs:
- name: Install dependencies from Conda
uses: mamba-org/setup-micromamba@v2
with:
create-args: mafft raxml fasttree iqtree vcftools seqkit sqlite tsv-utils biopython=${{ matrix.biopython-version }} python=${{ matrix.python-version }}
create-args: mafft raxml fasttree iqtree vcftools seqkit sqlite tsv-utils biopython=${{ matrix.biopython-version }} python=${{ matrix.python-version }} numpy=1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should rebase this and resolve merge conflicts

condarc: |
channels:
- conda-forge
Expand All @@ -85,19 +82,49 @@ jobs:

# Replace the Conda Augur installation with the local version.
- run: pip install .[dev]
- run: pip list
- run: conda info
- run: conda list
- run: pytest --cov=augur
- run: cram tests/
env:
AUGUR: coverage run -a ${{ github.workspace }}/bin/augur
# Only upload coverage for one job
- if: matrix.python-version == '3.11' && matrix.biopython-version == ''

# Set coverage environment variables only for the coverage job
- name: Set coverage environment variables
if: matrix.python-version == '3.11' && matrix.biopython-version == ''
run: |
echo "COVERAGE_FILE=${{ github.workspace }}/.coverage@python=${{ matrix.python-version }},biopython=${{ matrix.biopython-version || 'latest' }}" >> "$GITHUB_ENV"
echo "COVERAGE_RCFILE=${{ github.workspace }}/.coveragerc" >> "$GITHUB_ENV"
if python3 -c 'import sys; print(sys.version_info >= (3, 14))' | grep -q True; then
echo "Using sysmon for coverage to reduce overhead"
echo COVERAGE_CORE=sysmon >> "$GITHUB_ENV"
else
echo "Using default coverage collection method"
fi

- name: Run pytest
run: |
if [[ -n "${COVERAGE_FILE:-}" ]]; then
echo "Running pytest with coverage enabled"
pytest --cov=augur
else
echo "Running pytest without coverage"
pytest --no-cov
fi
- name: Run cram tests
run: |
if [[ -n "${COVERAGE_FILE:-}" ]]; then
echo "Running cram tests with coverage enabled"
export AUGUR="coverage run -a ${{ github.workspace }}/bin/augur"
else
echo "Running cram tests without coverage"
export AUGUR="${{ github.workspace }}/bin/augur"
fi
cram tests/
- name: Upload coverage
if: env.COVERAGE_FILE
uses: actions/upload-artifact@v4
with:
name: coverage
include-hidden-files: true
path: "${{ env.COVERAGE_FILE }}"
path: "${{ github.workspace }}/.coverage@python=${{ matrix.python-version }},biopython=${{ matrix.biopython-version || 'latest' }}"

# Replicating pathogen-repo-ci workflow because we decided not to support
# local versions of Augur in the centralized workflow
Expand Down
36 changes: 28 additions & 8 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
#!/bin/sh

# Default to running all tests.
# Default to running all tests without coverage.
partial_test=0
run_coverage=0

# Check if user explicitly requests coverage
case "$@" in
*--cov*) run_coverage=1 ;;
esac

# If user requests a subset of tests for pytest, note this preference to avoid
# running other tests.
case "$@" in
*-k*) partial_test=1 ;;
esac

if [ "$partial_test" = 1 ]; then
# skip test coverage when running a subset of the test suite
coverage_arg='--no-cov'
if [ "$run_coverage" = 1 ]; then
# Remove --cov from args since pytest will handle coverage via --cov=augur
echo "Running tests with coverage enabled, remove --cov to disable"
filtered_args=$(echo "$*" | sed 's/--cov//g')
coverage_arg='--cov=augur'

# Set env variable COVERAGE_CORE to sysmon for coverage
# This reduces overhead of coverage collection
# But only if Python version >3.14
if python3 -c 'import sys; print(sys.version_info >= (3, 14))' | grep -q True; then
echo "Using sysmon for coverage to reduce overhead"
export COVERAGE_CORE=sysmon
else
echo "Using default coverage collection method"
fi
else
coverage_arg=''
# Default to no coverage
echo "Running tests without coverage, use --cov to enable"
filtered_args="$*"
coverage_arg='--no-cov'
fi

echo "Running unit tests and doctests with pytest"
python3 -m pytest $coverage_arg "$@"
python3 -m pytest $coverage_arg $filtered_args

# Only run functional tests if we are not running a subset of tests for pytest.
if [ "$partial_test" = 0 ]; then
echo "Running functional tests with cram"
cram tests/
else
echo "Skipping functional tests when running a subset of unit tests"
echo "Skipping functional (cram) tests when running a subset of unit tests"
fi

exit $?
Loading