Skip to content

Commit

Permalink
Use fixture for installed solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
phschiele committed Sep 2, 2023
1 parent 9041b38 commit ecdc6b3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

from pathlib import Path

import cvxpy as cp
import pytest


@pytest.fixture(scope="session", name="resource_dir")
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
7 changes: 0 additions & 7 deletions tests/test_markowitz/test_portfolios/test_max_sharpe.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import annotations

import os

import cvxpy as cp
import numpy as np
import pytest

Expand Down Expand Up @@ -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]])),
Expand Down
11 changes: 0 additions & 11 deletions tests/test_markowitz/test_portfolios/test_min_var.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import annotations

import os

import cvxpy as cp
import numpy as np
import pytest

Expand Down Expand Up @@ -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(
Expand All @@ -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()

Expand Down
6 changes: 0 additions & 6 deletions tests/test_markowitz/test_risk/test_cvar/test_cvar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import annotations

import os

import cvxpy as cp
import numpy as np
import pytest

Expand All @@ -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)

Expand Down
5 changes: 0 additions & 5 deletions tests/test_markowitz/test_risk/test_factor/test_factor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import os

import cvxpy as cp
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ecdc6b3

Please sign in to comment.