From 7afbe60b83024f961b0c40a3b48cfc6584f48db1 Mon Sep 17 00:00:00 2001 From: "Austin E. Soplata" Date: Fri, 8 Nov 2024 09:22:05 -0500 Subject: [PATCH 1/3] feat: add marks and change pytest runs for pll --- .github/workflows/unix_unit_tests.yml | 14 +++++++++----- hnn_core/tests/test_dipole.py | 1 + hnn_core/tests/test_extracellular.py | 1 + hnn_core/tests/test_gui.py | 1 + hnn_core/tests/test_parallel_backends.py | 2 ++ pytest.ini | 2 ++ setup.py | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unix_unit_tests.yml b/.github/workflows/unix_unit_tests.yml index 1e6ff5330..90b79c386 100644 --- a/.github/workflows/unix_unit_tests.yml +++ b/.github/workflows/unix_unit_tests.yml @@ -39,14 +39,14 @@ uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - + - name: Install Python dependencies shell: bash -el {0} run: | if [ ${{ matrix.os }} == 'macos-latest' ]; then python -m pip install --upgrade pip conda install --yes -c conda-forge mpi4py openmpi - elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then python -m pip install --upgrade pip python -m pip install mpi4py fi @@ -58,11 +58,15 @@ shell: bash -el {0} run: | flake8 --count hnn_core - - name: Test with pytest + - name: Test embarrassingly parallel tests with pytest + shell: bash -el {0} + run: | + python -m pytest ./hnn_core/tests/ -m "not already_parallel" -n auto --cov=hnn_core --cov-report=xml + - name: Test true parallel tests with pytest shell: bash -el {0} run: | - python -m pytest ./hnn_core/tests/ --cov=hnn_core --cov-report=xml + python -m pytest ./hnn_core/tests/ -m "already_parallel" --cov=hnn_core --cov-report=xml --cov-append - name: Upload coverage to Codecov shell: bash -el {0} run: | - bash <(curl -s https://codecov.io/bash) -f ./coverage.xml \ No newline at end of file + bash <(curl -s https://codecov.io/bash) -f ./coverage.xml diff --git a/hnn_core/tests/test_dipole.py b/hnn_core/tests/test_dipole.py index 9beea6b9d..cb141a5dd 100644 --- a/hnn_core/tests/test_dipole.py +++ b/hnn_core/tests/test_dipole.py @@ -213,6 +213,7 @@ def test_dipole_simulation(): @requires_mpi4py @requires_psutil +@pytest.mark.already_parallel def test_cell_response_backends(run_hnn_core_fixture): """Test cell_response outputs across backends.""" diff --git a/hnn_core/tests/test_extracellular.py b/hnn_core/tests/test_extracellular.py index ae97083f1..1b729bd6b 100644 --- a/hnn_core/tests/test_extracellular.py +++ b/hnn_core/tests/test_extracellular.py @@ -170,6 +170,7 @@ def test_transfer_resistance(): @requires_mpi4py @requires_psutil +@pytest.mark.already_parallel def test_extracellular_backends(run_hnn_core_fixture): """Test extracellular outputs across backends.""" # calculation of CSD requires >=4 electrode contacts diff --git a/hnn_core/tests/test_gui.py b/hnn_core/tests/test_gui.py index 1349c6629..c56212434 100644 --- a/hnn_core/tests/test_gui.py +++ b/hnn_core/tests/test_gui.py @@ -366,6 +366,7 @@ def test_gui_init_network(setup_gui): @requires_mpi4py @requires_psutil +@pytest.mark.already_parallel def test_gui_run_simulation_mpi(): """Test if run button triggers simulation with MPIBackend.""" gui = HNNGUI() diff --git a/hnn_core/tests/test_parallel_backends.py b/hnn_core/tests/test_parallel_backends.py index b6e9f7ed6..533b46b47 100644 --- a/hnn_core/tests/test_parallel_backends.py +++ b/hnn_core/tests/test_parallel_backends.py @@ -77,6 +77,7 @@ def test_gid_assignment(): @pytest.mark.incremental +@pytest.mark.already_parallel class TestParallelBackends(): dpls_reduced_mpi = None dpls_reduced_default = None @@ -241,6 +242,7 @@ def test_compare_hnn_core(self, run_hnn_core_fixture, backend, n_jobs=1): # class marked incremental @requires_mpi4py @requires_psutil +@pytest.mark.already_parallel def test_mpi_failure(run_hnn_core_fixture): """Test that an MPI failure is handled and messages are printed""" # this MPI parameter will cause a MPI job to fail diff --git a/pytest.ini b/pytest.ini index c00948689..704b1b1f8 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,5 @@ [pytest] markers = + already_parallel: tests that should not be run across multiple cores by pytest incremental: run tests with prerequisites in incremental order + diff --git a/setup.py b/setup.py index 8eea61f7d..8887be1ed 100644 --- a/setup.py +++ b/setup.py @@ -77,7 +77,7 @@ def run(self): extras = { 'opt': ['scikit-learn'], 'parallel': ['joblib', 'psutil'], - 'test': ['flake8', 'pytest', 'pytest-cov', ], + 'test': ['flake8', 'pytest', 'pytest-cov', 'pytest-xdist'], 'docs': ['mne', 'nibabel', 'pooch', 'tdqm', 'sphinx', 'sphinx-gallery', 'sphinx_bootstrap_theme', 'sphinx-copybutton', From 02e43912662d6cfd68a1f0e0c46b0ccfddc3dfac Mon Sep 17 00:00:00 2001 From: "Austin E. Soplata" Date: Fri, 8 Nov 2024 14:34:58 -0500 Subject: [PATCH 2/3] Improve mark name, duplicate test cmds into Make --- .github/workflows/unix_unit_tests.yml | 8 ++++---- Makefile | 3 ++- hnn_core/tests/test_dipole.py | 2 +- hnn_core/tests/test_extracellular.py | 2 +- hnn_core/tests/test_gui.py | 2 +- hnn_core/tests/test_parallel_backends.py | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/unix_unit_tests.yml b/.github/workflows/unix_unit_tests.yml index 90b79c386..7648f8000 100644 --- a/.github/workflows/unix_unit_tests.yml +++ b/.github/workflows/unix_unit_tests.yml @@ -58,14 +58,14 @@ shell: bash -el {0} run: | flake8 --count hnn_core - - name: Test embarrassingly parallel tests with pytest + - name: Test non-MPI, embarrassingly parallel tests with pytest shell: bash -el {0} run: | - python -m pytest ./hnn_core/tests/ -m "not already_parallel" -n auto --cov=hnn_core --cov-report=xml - - name: Test true parallel tests with pytest + python -m pytest ./hnn_core/tests/ -m "not uses_mpi" -n auto --cov=hnn_core --cov-report=xml + - name: Test MPI-using parallel tests with pytest shell: bash -el {0} run: | - python -m pytest ./hnn_core/tests/ -m "already_parallel" --cov=hnn_core --cov-report=xml --cov-append + python -m pytest ./hnn_core/tests/ -m "uses_mpi" --cov=hnn_core --cov-report=xml --cov-append - name: Upload coverage to Codecov shell: bash -el {0} run: | diff --git a/Makefile b/Makefile index 9970666ed..67e1d3a99 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ check-manifest: check-manifest test: flake - pytest . + pytest ./hnn_core/tests/ -m "not uses_mpi" -n auto + pytest ./hnn_core/tests/ -m "uses_mpi" flake: @if command -v flake8 > /dev/null; then \ diff --git a/hnn_core/tests/test_dipole.py b/hnn_core/tests/test_dipole.py index cb141a5dd..3e9c033be 100644 --- a/hnn_core/tests/test_dipole.py +++ b/hnn_core/tests/test_dipole.py @@ -213,7 +213,7 @@ def test_dipole_simulation(): @requires_mpi4py @requires_psutil -@pytest.mark.already_parallel +@pytest.mark.uses_mpi def test_cell_response_backends(run_hnn_core_fixture): """Test cell_response outputs across backends.""" diff --git a/hnn_core/tests/test_extracellular.py b/hnn_core/tests/test_extracellular.py index 1b729bd6b..1e2b525ef 100644 --- a/hnn_core/tests/test_extracellular.py +++ b/hnn_core/tests/test_extracellular.py @@ -170,7 +170,7 @@ def test_transfer_resistance(): @requires_mpi4py @requires_psutil -@pytest.mark.already_parallel +@pytest.mark.uses_mpi def test_extracellular_backends(run_hnn_core_fixture): """Test extracellular outputs across backends.""" # calculation of CSD requires >=4 electrode contacts diff --git a/hnn_core/tests/test_gui.py b/hnn_core/tests/test_gui.py index c56212434..b54225b3f 100644 --- a/hnn_core/tests/test_gui.py +++ b/hnn_core/tests/test_gui.py @@ -366,7 +366,7 @@ def test_gui_init_network(setup_gui): @requires_mpi4py @requires_psutil -@pytest.mark.already_parallel +@pytest.mark.uses_mpi def test_gui_run_simulation_mpi(): """Test if run button triggers simulation with MPIBackend.""" gui = HNNGUI() diff --git a/hnn_core/tests/test_parallel_backends.py b/hnn_core/tests/test_parallel_backends.py index 533b46b47..a8dec20a7 100644 --- a/hnn_core/tests/test_parallel_backends.py +++ b/hnn_core/tests/test_parallel_backends.py @@ -77,7 +77,7 @@ def test_gid_assignment(): @pytest.mark.incremental -@pytest.mark.already_parallel +@pytest.mark.uses_mpi class TestParallelBackends(): dpls_reduced_mpi = None dpls_reduced_default = None @@ -242,7 +242,7 @@ def test_compare_hnn_core(self, run_hnn_core_fixture, backend, n_jobs=1): # class marked incremental @requires_mpi4py @requires_psutil -@pytest.mark.already_parallel +@pytest.mark.uses_mpi def test_mpi_failure(run_hnn_core_fixture): """Test that an MPI failure is handled and messages are printed""" # this MPI parameter will cause a MPI job to fail From 06743faa5747bbbfd10722cf33ea6c75a12e74e9 Mon Sep 17 00:00:00 2001 From: "Austin E. Soplata" Date: Mon, 16 Dec 2024 15:58:07 -0500 Subject: [PATCH 3/3] chore: update pytest custom marker metadata --- pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index 704b1b1f8..97a736cf5 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] markers = - already_parallel: tests that should not be run across multiple cores by pytest + uses_mpi: tests which should NOT be run in an embarrassingly-parallel fashion incremental: run tests with prerequisites in incremental order