Skip to content

Commit

Permalink
[tests/python] Properly gate some tests using pytest.mark.skipif
Browse files Browse the repository at this point in the history
[cmake] Remove some tests from list of Python tests depending on detected features
  • Loading branch information
ManifoldFR committed Sep 19, 2024
1 parent 4c5a80f commit a4e789a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 5 additions & 5 deletions tests/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ file(
if(NOT BUILD_CROCODDYL_COMPAT)
list(REMOVE_ITEM PYTHON_TESTS test_compat_croc.py)
endif()
if(NOT BUILD_WITH_PINOCCHIO_PYTHON_BINDINGS)
list(REMOVE_ITEM PYTHON_TESTS test_constrained_dynamics.py)
if(NOT BUILD_WITH_PINOCCHIO_SUPPORT)
list(REMOVE_ITEM PYTHON_TESTS test_center_of_mass.py)
list(REMOVE_ITEM PYTHON_TESTS test_frames.py)
endif()
if(NOT PINOCCHIO_V3)
list(REMOVE_ITEM PYTHON_TESTS test_rollout.py)
elseif(NOT PINOCCHIO_V3)
# Pinocchio support, but not Pinocchio 3
list(REMOVE_ITEM PYTHON_TESTS test_constrained_dynamics.py)
list(REMOVE_ITEM PYTHON_TESTS test_frames.py)
endif()
make_directory(${CMAKE_CURRENT_BINARY_DIR})

Expand Down
12 changes: 11 additions & 1 deletion tests/python/test_continuous_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import numpy as np
import aligator
from aligator import dynamics, manifolds
from pinocchio import Quaternion
from eigenpy import Quaternion
from utils import finite_diff, infNorm, create_multibody_ode

epsilon = 1e-6
aligator.seed(42)
np.random.seed(42)
HAS_PINOCCHIO = aligator.has_pinocchio_features()


class MyODE(dynamics.ODEAbstract):
Expand Down Expand Up @@ -71,6 +72,9 @@ def test_custom_ode():
assert len(xs) == 11


@pytest.mark.skipif(
not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
)
def test_multibody_free():
ode = create_multibody_ode(True)
if ode is None:
Expand Down Expand Up @@ -304,6 +308,9 @@ def test_continuous_centroidal_diff():
assert np.allclose(Judiff, Ju0, epsilon), "err={}".format(infNorm(Judiff - Ju0))


@pytest.mark.skipif(
not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
)
def test_kinodynamics():
import pinocchio as pin

Expand Down Expand Up @@ -337,6 +344,9 @@ def test_kinodynamics():
ode.dForward(x0, u0, data)


@pytest.mark.skipif(
not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
)
def test_kinodynamics_diff():
import pinocchio as pin

Expand Down
5 changes: 3 additions & 2 deletions tests/python/test_finite_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def test_compute_jac_vs():
assert np.allclose(fdata1.Jy, fdata1b.Jy, 1e-2)


@pytest.mark.skipif(not HAS_PINOCCHIO, reason="Pinocchio bindings not present.")
@pytest.mark.skipif(
not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio."
)
def test_compute_jac_multibody():
model = pin.buildSampleModelHumanoid()
space = manifolds.MultibodyConfiguration(model)
Expand Down Expand Up @@ -87,7 +89,6 @@ def test_compute_cost_se3():


if __name__ == "__main__":
import pytest
import sys

sys.exit(pytest.main(sys.argv))
4 changes: 2 additions & 2 deletions tests/python/test_frames.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test function related to frames.
Test function related to Pinocchio frames.
This test is not added to CTest when CMake does not detect Pinocchio.
"""

import aligator
Expand Down Expand Up @@ -194,4 +195,3 @@ def test_fly_high():
import pytest

sys.exit(pytest.main(sys.argv))
# test_frame_placement()

0 comments on commit a4e789a

Please sign in to comment.