File: conftest.py

package info (click to toggle)
python-cobra 0.29.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,512 kB
  • sloc: python: 14,703; xml: 12,841; makefile: 137; sh: 32
file content (38 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Define module level fixtures."""

from typing import TYPE_CHECKING, Tuple

import pytest

from cobra.util.solver import solvers


if TYPE_CHECKING:
    from cobra import Model, Solution


solver_trials = [
    "glpk",
    pytest.param(
        "cplex",
        marks=pytest.mark.skipif(
            "cplex" not in solvers, reason="No CPLEX found on PYTHONPATH"
        ),
    ),
    pytest.param(
        "gurobi",
        marks=pytest.mark.skipif(
            "gurobi" not in solvers, reason="No Gurobi found on PYTHONPATH"
        ),
    ),
]


@pytest.fixture(scope="function", params=solver_trials)
def solved_model(
    request: pytest.FixtureRequest, model: "Model"
) -> Tuple["Solution", "Model"]:
    """Return solved model."""
    model.solver = request.param
    solution = model.optimize()
    return solution, model