Skip to content

Commit 02ea89c

Browse files
Merge pull request #157 from davidrudlstorfer/add_pytest_infrastructure
Add pytest framework to MeshPy - Provide pytest infrastructure including - Tags/Markers for different test scenarious - Fixtures to simplify testing - Comparison utils for all sort of types - Port rotation tests to pytest - Port cosserat curve to pytest - Update github actions - Simplify testing procedure - Update artifact upload - Remove files from old testing framework
2 parents 5db8fd6 + 85deef8 commit 02ea89c

18 files changed

+1119
-977
lines changed

.github/actions/run_performance_tests/action.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/actions/run_tests/action.yml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,27 @@ inputs:
99
description: Command to source the virtual environment
1010
required: false
1111
default: ""
12-
require_four_c:
13-
description: Fail if the 4C tests can not be performed
12+
additional-pytest-flags:
13+
description: Additional flags to pass to pytest, i.e., markers
1414
required: false
15-
default: 1
16-
require_arborx:
17-
description: Fail if the ArborX tests can not be performed
18-
required: false
19-
default: 1
20-
require_cubitpy:
21-
description: Fail if the CubitPy tests can not be performed
22-
required: false
23-
default: 1
24-
coverage_config:
25-
description: Config file to use for coverage analysis
26-
required: false
27-
default: "coverage.config"
15+
default: ""
2816
runs:
2917
using: composite
3018
steps:
3119
- name: MeshPy testing
3220
shell: bash
3321
env:
3422
MESHPY_FOUR_C_EXE: /home/user/4C/build/4C
35-
TESTING_GITHUB: 1
36-
TESTING_GITHUB_4C: ${{ inputs.require_four_c }}
37-
TESTING_GITHUB_ARBORX: ${{ inputs.require_arborx }}
38-
TESTING_GITHUB_CUBITPY: ${{ inputs.require_cubitpy }}
3923
CUBIT_ROOT: /imcs/public/compsim/opt/cubit-15.2
4024
OMPI_MCA_rmaps_base_oversubscribe: 1
25+
PERFORMANCE_TESTING_HOST: github-sisyphos-docker
4126
run: |
4227
cd ${GITHUB_WORKSPACE}
4328
${{ inputs.source-command }}
4429
pip install ${{ inputs.install-command }}
4530
python --version
4631
pip list
47-
cd tests
48-
coverage run --rcfile=${{ inputs.coverage_config }} testing_main.py
49-
coverage html
50-
coverage report
51-
coverage-badge -o htmlcov/coverage.svg
52-
coverage run --rcfile=${{ inputs.coverage_config }} -m pytest pytest_testing_cosserat_curve.py
53-
coverage report
32+
TEMP_DIR="${RUNNER_TEMP}/meshpy_pytest"
33+
mkdir -p "$TEMP_DIR"
34+
echo "PYTEST_TMPDIR=$TEMP_DIR" >> $GITHUB_ENV
35+
pytest --basetemp="$TEMP_DIR" ${{ inputs.additional-pytest-flags}}

.github/workflows/testing.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,12 @@ jobs:
4747
python-version: ${{ matrix.python-version }}
4848
- name: Run the test suite
4949
uses: ./.github/actions/run_tests
50-
with:
51-
require_four_c: 0
52-
require_arborx: 0
53-
require_cubitpy: 0
5450
- name: Upload test results on failure
5551
if: failure()
5652
uses: actions/upload-artifact@v4
5753
with:
5854
name: ${{github.job}}-${{ matrix.os-version }}-python${{ matrix.python-version }}-${{github.run_number}}
59-
path: ${{github.workspace}}/tests/testing-tmp/
55+
path: ${{ env.PYTEST_TMPDIR }}
6056

6157
meshpy-testing-cubitpy:
6258
name: self-hosted with CubitPy
@@ -75,14 +71,13 @@ jobs:
7571
uses: ./.github/actions/run_tests
7672
with:
7773
source-command: "source python-testing-environment/bin/activate"
78-
require_four_c: 0
79-
require_arborx: 0
74+
additional-pytest-flags: "--CubitPy"
8075
- name: Upload test results on failure
8176
if: failure()
8277
uses: actions/upload-artifact@v4
8378
with:
8479
name: ${{github.job}}-${{github.run_number}}
85-
path: ${{github.workspace}}/tests/testing-tmp/
80+
path: ${{ env.PYTEST_TMPDIR }}
8681

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

118112
meshpy-performance-testing:
119113
name: performance tests
@@ -129,5 +123,15 @@ jobs:
129123
uses: ./.github/actions/setup_virtual_python_environment
130124
with:
131125
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
132-
- name: Run the performance test suite
133-
uses: ./.github/actions/run_performance_tests
126+
- name: Run the test suite
127+
uses: ./.github/actions/run_tests
128+
with:
129+
source-command: "source python-testing-environment/bin/activate"
130+
install-command: ".[CI-CD]"
131+
additional-pytest-flags: "--performance-tests --exclude-standard-tests"
132+
- name: Upload test results on failure
133+
if: failure()
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: ${{github.job}}-${{github.run_number}}
137+
path: ${{ env.PYTEST_TMPDIR }}

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,21 @@ tests with 4C
8686
export MESHPY_FOUR_C_EXE=path_to_4C
8787
```
8888

89-
To check if everything worked as expected, run the tests
89+
To check if everything worked as expected, run the standard tests with
9090
```bash
91-
cd <path_to_meshpy>/tests
92-
python testing_main.py
91+
pytest
9392
```
9493

95-
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`)
94+
Further tests can be added with the following flags: `--4C`, `--ArborX`, `--CubitPy`, `--performance-tests`.
95+
These can be arbitrarily combined, for example
9696
```bash
97-
cd <path_to_meshpy>/tests
98-
python performance_testing.py
97+
pytest --4C --CubityPy
98+
```
99+
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.
100+
101+
Finally, the base tests can be deactivated with `--exclude-standard-tests`. For example to just run the CubitPy tests execute
102+
```bash
103+
pytest --CubitPy --exclude-standard-tests
99104
```
100105

101106
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:
@@ -122,8 +127,8 @@ cd <path_to_meshpy>/build/geometric_search
122127
cmake ../../meshpy/geometric_search/src/
123128
make -j4
124129
```
130+
125131
If the ArborX extension is working correctly can be checked by running the geometric search tests
126132
```bash
127-
cd <path_to_meshpy>/tests
128-
python testing_geometric_search.py
133+
pytest --ArborX
129134
```

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
"numpy-quaternion",
4040
"pre-commit",
4141
"pytest",
42+
"pytest-cov",
4243
"pyvista",
4344
"pyvista_utils@git+https://github.com/isteinbrecher/pyvista_utils.git@main",
4445
"scipy",
@@ -55,3 +56,13 @@ CI-CD = [
5556
"cubitpy@git+https://github.com/imcs-compsim/cubitpy.git@main",
5657
"setuptools" # Needed for coverage-badge
5758
]
59+
60+
[tool.pytest.ini_options]
61+
testpaths = ["tests"]
62+
addopts = "-p pytest_cov --cov-report=term --cov-report=html --cov-fail-under=0 --cov=meshpy/ --cov=tutorial/ --cov-append"
63+
markers = [
64+
"fourc: tests in combination with 4C",
65+
"arborx: tests in combination with ArborX",
66+
"cubitpy: tests in combination with CubitPy",
67+
"performance: performance tests of MeshPy"
68+
]

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2929
# SOFTWARE.
3030
# -----------------------------------------------------------------------------
31-
"""This module defines testing functionality for MeshPy."""
31+
"""This module tests MeshPy."""

0 commit comments

Comments
 (0)