Skip to content

Commit

Permalink
Switch to using module-level fixture for tmp_path workdir
Browse files Browse the repository at this point in the history
  • Loading branch information
lbianchi-lbl committed Sep 19, 2024
1 parent ac4b833 commit 33edfd6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions idaes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions idaes/core/surrogate/tests/test_pysmo_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -228,7 +228,6 @@
)


@pytest.mark.usefixtures("run_class_in_tmp_path")
class TestSurrogateTrainingResult:
@pytest.fixture
def pysmo_output_pr(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 33edfd6

Please sign in to comment.