ci: output failing test details via junit XML on failure #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [master, develop] | |
| pull_request: | |
| branches: [master, develop] | |
| jobs: | |
| test: | |
| name: Python ${{ matrix.python-version }} / ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| python-version: ["3.10", "3.11", "3.12"] | |
| defaults: | |
| run: | |
| shell: bash -l {0} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up conda (miniforge) | |
| uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| miniforge-version: latest | |
| python-version: ${{ matrix.python-version }} | |
| activate-environment: mastermsm-test | |
| auto-activate-base: false | |
| - name: Install dependencies | |
| run: | | |
| conda install -y -c conda-forge \ | |
| numpy scipy matplotlib networkx \ | |
| mdtraj scikit-learn | |
| pip install pytest | |
| pip install -e . | |
| - name: Show package versions | |
| run: | | |
| python -c " | |
| import numpy, scipy, mdtraj, networkx, sklearn | |
| print('numpy :', numpy.__version__) | |
| print('scipy :', scipy.__version__) | |
| print('mdtraj :', mdtraj.__version__) | |
| print('networkx :', networkx.__version__) | |
| print('sklearn :', sklearn.__version__) | |
| " | |
| - name: Run tests | |
| run: pytest mastermsm/test/ -v --tb=long --junit-xml=test-results.xml | |
| - name: Show test results on failure | |
| if: failure() | |
| run: | | |
| python3 -c " | |
| import xml.etree.ElementTree as ET, sys | |
| try: | |
| tree = ET.parse('test-results.xml') | |
| for tc in tree.iter('testcase'): | |
| fail = tc.find('failure') or tc.find('error') | |
| if fail is not None: | |
| print('FAILED:', tc.attrib.get('classname',''), '::', tc.attrib.get('name','')) | |
| print(fail.text) | |
| print() | |
| except Exception as e: | |
| print('Could not parse results:', e) | |
| " |