diff --git a/tests/conftest.py b/tests/conftest.py index 934342b9..24b012ea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ from pathlib import Path +import cvxpy as cp import pytest @@ -10,3 +11,10 @@ def resource_fixture(): """resource fixture""" return Path(__file__).parent / "resources" + + +@pytest.fixture( + params=[s for s in [cp.ECOS, cp.CLARABEL, cp.MOSEK] if s in cp.installed_solvers()] +) +def solver(request): + return request.param diff --git a/tests/test_markowitz/test_portfolios/test_max_sharpe.py b/tests/test_markowitz/test_portfolios/test_max_sharpe.py index 4f6bb5f5..9abd6e96 100644 --- a/tests/test_markowitz/test_portfolios/test_max_sharpe.py +++ b/tests/test_markowitz/test_portfolios/test_max_sharpe.py @@ -1,8 +1,5 @@ from __future__ import annotations -import os - -import cvxpy as cp import numpy as np import pytest @@ -49,11 +46,7 @@ def test_models_problem(problem): assert problem.model.keys() == {M.BOUND_ASSETS, M.RETURN, M.RISK} -@pytest.mark.parametrize("solver", [cp.ECOS, cp.CLARABEL, cp.MOSEK]) def test_max_sharpe(solver, problem): - if os.getenv("CI", False) and solver == cp.MOSEK: - pytest.skip("Skipping MOSEK test on CI") - problem.update( **{ D.CHOLESKY: cholesky(np.array([[1.0, 0.6], [0.6, 2.0]])), diff --git a/tests/test_markowitz/test_portfolios/test_min_var.py b/tests/test_markowitz/test_portfolios/test_min_var.py index b6403ecf..4663825e 100644 --- a/tests/test_markowitz/test_portfolios/test_min_var.py +++ b/tests/test_markowitz/test_portfolios/test_min_var.py @@ -1,8 +1,5 @@ from __future__ import annotations -import os - -import cvxpy as cp import numpy as np import pytest @@ -61,11 +58,7 @@ def test_variables(problem): assert problem.variables.keys() == {D.WEIGHTS, D._ABS} -@pytest.mark.parametrize("solver", [cp.ECOS, cp.MOSEK, cp.CLARABEL]) def test_min_var(solver): - if os.getenv("CI", False) and solver == cp.MOSEK: - pytest.skip("Skipping MOSEK test on CI") - problem = MinVar(assets=4).build() problem.update( @@ -88,11 +81,7 @@ def test_min_var(solver): assert objective == pytest.approx(0.9354143, abs=1e-5) -@pytest.mark.parametrize("solver", [cp.ECOS, cp.MOSEK, cp.CLARABEL]) def test_min_var_robust(solver): - if os.getenv("CI", False) and solver == cp.MOSEK: - pytest.skip("Skipping MOSEK test on CI") - # define the problem problem = MinVar(assets=4).build() diff --git a/tests/test_markowitz/test_risk/test_cvar/test_cvar.py b/tests/test_markowitz/test_risk/test_cvar/test_cvar.py index 78aa4373..05c84f15 100644 --- a/tests/test_markowitz/test_risk/test_cvar/test_cvar.py +++ b/tests/test_markowitz/test_risk/test_cvar/test_cvar.py @@ -1,8 +1,5 @@ from __future__ import annotations -import os - -import cvxpy as cp import numpy as np import pytest @@ -12,11 +9,8 @@ from cvx.markowitz.risk import CVar -@pytest.mark.parametrize("solver", [cp.ECOS, cp.MOSEK, cp.CLARABEL]) def test_estimate_risk(solver): """Test the estimate() method""" - if os.getenv("CI", False) and solver == cp.MOSEK: - pytest.skip("Skipping MOSEK test on CI") model = CVar(alpha=0.95, rows=50, assets=14) diff --git a/tests/test_markowitz/test_risk/test_factor/test_factor.py b/tests/test_markowitz/test_risk/test_factor/test_factor.py index e0a8c562..28796443 100644 --- a/tests/test_markowitz/test_risk/test_factor/test_factor.py +++ b/tests/test_markowitz/test_risk/test_factor/test_factor.py @@ -1,7 +1,5 @@ from __future__ import annotations -import os - import cvxpy as cp import numpy as np import pandas as pd @@ -59,11 +57,8 @@ def test_minvar(returns): assert problem.is_dpp() -@pytest.mark.parametrize("solver", [cp.ECOS, cp.MOSEK, cp.CLARABEL]) def test_estimate_risk(solver): """Test the estimate() method""" - if os.getenv("CI", False) and solver == cp.MOSEK: - pytest.skip("Skipping MOSEK test on CI") np.random.seed(42)