Skip to content

Commit 6152f53

Browse files
committed
use pytest temppath instead of namedtemppath
1 parent 0505224 commit 6152f53

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

test/test_solvers.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
@author: sid
66
"""
77

8-
from pathlib import Path
9-
from tempfile import NamedTemporaryFile
10-
118
import pytest
129

1310
from linopy import solvers
@@ -46,22 +43,22 @@
4643

4744

4845
@pytest.mark.parametrize("solver", solvers.available_solvers)
49-
def test_free_mps_solution_parsing(solver):
46+
def test_free_mps_solution_parsing(solver, tmp_path):
5047
try:
5148
solver_enum = solvers.SolverName(solver.lower())
5249
solver_class = getattr(solvers, solver_enum.name)
5350
except ValueError:
5451
raise ValueError(f"Solver '{solver}' is not recognized")
5552

56-
with NamedTemporaryFile(mode="w", suffix=".mps", delete=False) as mps_file:
57-
mps_file.write(free_mps_problem)
58-
mps_file.close()
53+
# Write the MPS file to the temporary directory
54+
mps_file = tmp_path / "problem.mps"
55+
mps_file.write_text(free_mps_problem)
56+
57+
# Create a solution file path in the temporary directory
58+
sol_file = tmp_path / "solution.sol"
5959

60-
s = solver_class()
61-
with NamedTemporaryFile(suffix=".sol") as sol_file:
62-
result = s.solve_problem(
63-
problem_fn=Path(mps_file.name), solution_fn=Path(sol_file.name)
64-
)
60+
s = solver_class()
61+
result = s.solve_problem(problem_fn=mps_file, solution_fn=sol_file)
6562

6663
assert result.status.is_ok
6764
assert result.solution.objective == 30.0

0 commit comments

Comments
 (0)