diff --git a/pyomo/contrib/iis/tests/test_mis.py b/pyomo/contrib/iis/tests/test_mis.py index 0561d647310..e4535e021b3 100644 --- a/pyomo/contrib/iis/tests/test_mis.py +++ b/pyomo/contrib/iis/tests/test_mis.py @@ -79,14 +79,24 @@ def _test_mis(solver_name): opt = pyo.SolverFactory(solver_name) # This test seems to fail on Windows as it unlinks the tempfile, so live with it - try: + # On a Windows machine, we will not use a temp dir and just try to delete the log file + if os.name == "nt": + print("we have nt") + file_name = f"{solver_name}_mis.log" + logger = logging.getLogger(f"test_mis_{solver_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) + + else: # not windows 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 + logger.setlevel(logging.INFO) fh = logging.FileHandler(file_name) fh.setLevel(logging.DEBUG) logger.addHandler(fh) @@ -94,9 +104,6 @@ def _test_mis(solver_name): 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__": unittest.main()