Skip to content

Commit

Permalink
catch the error that kills windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DLWoodruff committed Mar 30, 2024
1 parent 9f624d6 commit 2b7bfe7
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions pyomo/contrib/iis/tests/test_mis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def _get_infeasible_model():
m = pyo.ConcreteModel()
m = pyo.ConcreteModel("trivial4test")
m.x = pyo.Var(within=pyo.Binary)
m.y = pyo.Var(within=pyo.NonNegativeReals)

Expand Down Expand Up @@ -78,25 +78,25 @@ def _test_mis(solver_name):
m = _get_infeasible_model()
opt = pyo.SolverFactory(solver_name)

####TempfileManager.push()
####tmp_path = TempfileManager.create_tempdir()
with TempfileManager.new_context() as tmpmgr:
tmp_path = tmpmgr.mkdtemp()
file_name = os.path.join(tmp_path, f"{solver_name}_mis.log")
logger = logging.getLogger(f"test_mis_{solver_name}")
logger.setLevel(logging.INFO)
# create file handler which logs even debug messages
print(f"{file_name =}")
fh = logging.FileHandler(file_name)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)

mis.compute_infeasibility_explanation(m, opt, logger=logger)
_check_output(file_name)
# logging.getLogger().removeHandler(logging.getLogger().handlers[0])
logger.removeHandler(logger.handlers[0])

####TempfileManager.pop()
# This test seems to fail on Windows as it unlinks the tempfile, so live with it
try:
with TempfileManager.new_context() as tmpmgr:
print("start")
tmp_path = tmpmgr.mkdtemp()
file_name = os.path.join(tmp_path, f"{solver_name}_mis.log")
logger = logging.getLogger(f"test_mis_{solver_name}")
###logger.setLevel(logging.INFO)
# create file handler which logs even debug messages
fh = logging.FileHandler(file_name)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)

mis.compute_infeasibility_explanation(m, opt, logger=logger)
_check_output(file_name)

except PermissionError:
print("PerimssionError allowed for log file during test (Windows)")



if __name__ == "__main__":
Expand Down

0 comments on commit 2b7bfe7

Please sign in to comment.