Skip to content

Commit 304862c

Browse files
authored
pytest: Temporary Working Directory (#181)
* 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. * All the yielded results in the cwd context * Set basepath for input files (later) Not yet used, can be used in test files as ```py from conftest import basepath ```
1 parent a7d3abb commit 304862c

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

tests/conftest.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import itertools
4+
import os
45

56
import pytest
67

@@ -18,24 +19,28 @@
1819
if amr.Config.have_mpi:
1920
from mpi4py import MPI
2021

22+
# base path for input files
23+
basepath = os.getcwd()
24+
2125

2226
@pytest.fixture(autouse=True, scope="function")
23-
def amrex_init():
24-
amr.initialize(
25-
[
26-
# print AMReX status messages
27-
"amrex.verbose=2",
28-
# throw exceptions and create core dumps instead of
29-
# AMReX backtrace files: allows to attach to
30-
# debuggers
31-
"amrex.throw_exception=1",
32-
"amrex.signal_handling=0",
33-
# abort GPU runs if out-of-memory instead of swapping to host RAM
34-
# "abort_on_out_of_gpu_memory=1",
35-
]
36-
)
37-
yield
38-
amr.finalize()
27+
def amrex_init(tmpdir):
28+
with tmpdir.as_cwd():
29+
amr.initialize(
30+
[
31+
# print AMReX status messages
32+
"amrex.verbose=2",
33+
# throw exceptions and create core dumps instead of
34+
# AMReX backtrace files: allows to attach to
35+
# debuggers
36+
"amrex.throw_exception=1",
37+
"amrex.signal_handling=0",
38+
# abort GPU runs if out-of-memory instead of swapping to host RAM
39+
# "abort_on_out_of_gpu_memory=1",
40+
]
41+
)
42+
yield
43+
amr.finalize()
3944

4045

4146
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)