Skip to content

Add first version of pytest infrastructure #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/actions/run_performance_tests/action.yml

This file was deleted.

34 changes: 8 additions & 26 deletions .github/actions/run_tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,27 @@ inputs:
description: Command to source the virtual environment
required: false
default: ""
require_four_c:
description: Fail if the 4C tests can not be performed
additional-pytest-flags:
description: Additional flags to pass to pytest, i.e., markers
required: false
default: 1
require_arborx:
description: Fail if the ArborX tests can not be performed
required: false
default: 1
require_cubitpy:
description: Fail if the CubitPy tests can not be performed
required: false
default: 1
coverage_config:
description: Config file to use for coverage analysis
required: false
default: "coverage.config"
default: ""
runs:
using: composite
steps:
- name: MeshPy testing
shell: bash
env:
MESHPY_FOUR_C_EXE: /home/user/4C/build/4C
TESTING_GITHUB: 1
TESTING_GITHUB_4C: ${{ inputs.require_four_c }}
TESTING_GITHUB_ARBORX: ${{ inputs.require_arborx }}
TESTING_GITHUB_CUBITPY: ${{ inputs.require_cubitpy }}
CUBIT_ROOT: /imcs/public/compsim/opt/cubit-15.2
OMPI_MCA_rmaps_base_oversubscribe: 1
PERFORMANCE_TESTING_HOST: github-sisyphos-docker
run: |
cd ${GITHUB_WORKSPACE}
${{ inputs.source-command }}
pip install ${{ inputs.install-command }}
python --version
pip list
cd tests
coverage run --rcfile=${{ inputs.coverage_config }} testing_main.py
coverage html
coverage report
coverage-badge -o htmlcov/coverage.svg
coverage run --rcfile=${{ inputs.coverage_config }} -m pytest pytest_testing_cosserat_curve.py
coverage report
TEMP_DIR="${RUNNER_TEMP}/meshpy_pytest"
mkdir -p "$TEMP_DIR"
echo "PYTEST_TMPDIR=$TEMP_DIR" >> $GITHUB_ENV
pytest --basetemp="$TEMP_DIR" ${{ inputs.additional-pytest-flags}}
30 changes: 17 additions & 13 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Run the test suite
uses: ./.github/actions/run_tests
with:
require_four_c: 0
require_arborx: 0
require_cubitpy: 0
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{ matrix.os-version }}-python${{ matrix.python-version }}-${{github.run_number}}
path: ${{github.workspace}}/tests/testing-tmp/
path: ${{ env.PYTEST_TMPDIR }}

meshpy-testing-cubitpy:
name: self-hosted with CubitPy
Expand All @@ -75,14 +71,13 @@ jobs:
uses: ./.github/actions/run_tests
with:
source-command: "source python-testing-environment/bin/activate"
require_four_c: 0
require_arborx: 0
additional-pytest-flags: "--CubitPy"
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{github.run_number}}
path: ${{github.workspace}}/tests/testing-tmp/
path: ${{ env.PYTEST_TMPDIR }}

meshpy-testing-4C-arborx:
name: ubuntu-latest with 4C and ArborX
Expand All @@ -106,14 +101,13 @@ jobs:
with:
source-command: "source python-testing-environment/bin/activate"
install-command: "-e .[CI-CD]"
require_cubitpy: 0
coverage_config: "coverage_local.config"
additional-pytest-flags: "--4C --ArborX"
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{github.run_number}}
path: ${{github.workspace}}/tests/testing-tmp/
path: ${{ env.PYTEST_TMPDIR }}

meshpy-performance-testing:
name: performance tests
Expand All @@ -129,5 +123,15 @@ jobs:
uses: ./.github/actions/setup_virtual_python_environment
with:
python-exe: /home_local/github-runner/testing_lib/spack/opt/spack/linux-ubuntu20.04-icelake/gcc-9.4.0/python-3.12.1-qnjucxirxh534suwewl6drfa237u6t7w/bin/python
- name: Run the performance test suite
uses: ./.github/actions/run_performance_tests
- name: Run the test suite
uses: ./.github/actions/run_tests
with:
source-command: "source python-testing-environment/bin/activate"
install-command: ".[CI-CD]"
additional-pytest-flags: "--performance-tests --exclude-standard-tests"
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-${{github.run_number}}
path: ${{ env.PYTEST_TMPDIR }}
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,21 @@ tests with 4C
export MESHPY_FOUR_C_EXE=path_to_4C
```

To check if everything worked as expected, run the tests
To check if everything worked as expected, run the standard tests with
```bash
cd <path_to_meshpy>/tests
python testing_main.py
pytest
```

Also run the performance tests (the reference time values and host name might have to be adapted in the file `<path_to_meshpy>/tests/performance_testing.py`)
Further tests can be added with the following flags: `--4C`, `--ArborX`, `--CubitPy`, `--performance-tests`.
These can be arbitrarily combined, for example
```bash
cd <path_to_meshpy>/tests
python performance_testing.py
pytest --4C --CubityPy
```
executes the standard tests, the 4C tests and the CubitPy tests. Note that the reference time values for the performance tests might not suite your system.

Finally, the base tests can be deactivated with `--exclude-standard-tests`. For example to just run the CubitPy tests execute
```bash
pytest --CubitPy --exclude-standard-tests
```

Before you are ready to contribute to MeshPy, please make sure to install the `pre-commit hook` within the python environment to follow our style guides:
Expand All @@ -122,8 +127,8 @@ cd <path_to_meshpy>/build/geometric_search
cmake ../../meshpy/geometric_search/src/
make -j4
```

If the ArborX extension is working correctly can be checked by running the geometric search tests
```bash
cd <path_to_meshpy>/tests
python testing_geometric_search.py
pytest --ArborX
```
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies = [
"numpy-quaternion",
"pre-commit",
"pytest",
"pytest-cov",
"pyvista",
"pyvista_utils@git+https://github.com/isteinbrecher/pyvista_utils.git@main",
"scipy",
Expand All @@ -55,3 +56,13 @@ CI-CD = [
"cubitpy@git+https://github.com/imcs-compsim/cubitpy.git@main",
"setuptools" # Needed for coverage-badge
]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-p pytest_cov --cov-report=term --cov-report=html --cov-fail-under=0 --cov=meshpy/ --cov=tutorial/ --cov-append"
markers = [
"fourc: tests in combination with 4C",
"arborx: tests in combination with ArborX",
"cubitpy: tests in combination with CubitPy",
"performance: performance tests of MeshPy"
]
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""This module defines testing functionality for MeshPy."""
"""This module tests MeshPy."""
Loading
Loading