From c53e29c6c6a6c570f6962d8d107edb16c3d2974d Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 28 Aug 2023 14:20:27 -0700 Subject: [PATCH 1/3] pytest: Temporary Working Directory Tests can generate temporary output and directories, which might clash and/or need cleaning between tests. This changes the current working directory to a unique directory per test. --- tests/conftest.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f6dd861b..af22c9c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,20 +20,21 @@ @pytest.fixture(autouse=True, scope="function") -def amrex_init(): - amr.initialize( - [ - # print AMReX status messages - "amrex.verbose=2", - # throw exceptions and create core dumps instead of - # AMReX backtrace files: allows to attach to - # debuggers - "amrex.throw_exception=1", - "amrex.signal_handling=0", - # abort GPU runs if out-of-memory instead of swapping to host RAM - # "abort_on_out_of_gpu_memory=1", - ] - ) +def amrex_init(tmpdir): + with tmpdir.as_cwd(): + amr.initialize( + [ + # print AMReX status messages + "amrex.verbose=2", + # throw exceptions and create core dumps instead of + # AMReX backtrace files: allows to attach to + # debuggers + "amrex.throw_exception=1", + "amrex.signal_handling=0", + # abort GPU runs if out-of-memory instead of swapping to host RAM + # "abort_on_out_of_gpu_memory=1", + ] + ) yield amr.finalize() From b223a42c7c43df2d7ce00c2578f207785ad07903 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 28 Aug 2023 19:05:05 -0700 Subject: [PATCH 2/3] All the yielded results in the cwd context --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index af22c9c4..55adace2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,8 +35,8 @@ def amrex_init(tmpdir): # "abort_on_out_of_gpu_memory=1", ] ) - yield - amr.finalize() + yield + amr.finalize() @pytest.fixture(scope="function") From 2b63751a3f1f17c79ef58f9ebcc728c8dcb5eefd Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Tue, 29 Aug 2023 14:34:27 -0700 Subject: [PATCH 3/3] Set basepath for input files (later) Not yet used, can be used in test files as ```py from conftest import basepath ``` --- tests/conftest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 55adace2..c120fb75 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import itertools +import os import pytest @@ -18,6 +19,9 @@ if amr.Config.have_mpi: from mpi4py import MPI +# base path for input files +basepath = os.getcwd() + @pytest.fixture(autouse=True, scope="function") def amrex_init(tmpdir):