diff --git a/idaes/conftest.py b/idaes/conftest.py index 871d25a3fa..57d9103b04 100644 --- a/idaes/conftest.py +++ b/idaes/conftest.py @@ -270,6 +270,22 @@ def run_class_in_tmp_path( os.chdir(prev_workdir) +@pytest.fixture(scope="module") +def run_module_in_tmp_path( + request: pytest.FixtureRequest, tmp_path_factory: pytest.TempPathFactory +): + prev_workdir = os.getcwd() + + modname = request.module.__name__ + + tmp_path = tmp_path_factory.mktemp(modname, numbered=True) + try: + os.chdir(tmp_path) + yield + finally: + os.chdir(prev_workdir) + + def _get_repo_root_dir() -> Union[Path, None]: try: text = subprocess.check_output( diff --git a/idaes/core/surrogate/tests/test_pysmo_surrogate.py b/idaes/core/surrogate/tests/test_pysmo_surrogate.py index fe1228331c..cc22ac9cbc 100644 --- a/idaes/core/surrogate/tests/test_pysmo_surrogate.py +++ b/idaes/core/surrogate/tests/test_pysmo_surrogate.py @@ -46,7 +46,7 @@ from idaes.core.surrogate.metrics import compute_fit_metrics -dirpath = Path(__file__).parent.resolve() +pytestmark = pytest.mark.usefixtures("run_module_in_tmp_path") # String representation of json output for testing @@ -228,7 +228,6 @@ ) -@pytest.mark.usefixtures("run_class_in_tmp_path") class TestSurrogateTrainingResult: @pytest.fixture def pysmo_output_pr(self): diff --git a/idaes/models_extra/power_generation/flowsheets/test/test_subcritical_boiler.py b/idaes/models_extra/power_generation/flowsheets/test/test_subcritical_boiler.py index ed227a1d49..de56d59ed6 100644 --- a/idaes/models_extra/power_generation/flowsheets/test/test_subcritical_boiler.py +++ b/idaes/models_extra/power_generation/flowsheets/test/test_subcritical_boiler.py @@ -35,12 +35,14 @@ solver = get_solver() +pytestmark = pytest.mark.usefixtures("run_module_in_tmp_path") + + @pytest.fixture(scope="module") def model(): return main() -@pytest.mark.usefixtures("run_in_tmp_path") @pytest.mark.skipif(not helmholtz_available(), reason="General Helmholtz not available") @pytest.mark.component def test_basic_build(model):