Skip to content

Commit

Permalink
pytest: Temporary Working Directory (#181)
Browse files Browse the repository at this point in the history
* 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
```
  • Loading branch information
ax3l authored Aug 30, 2023
1 parent a7d3abb commit 304862c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import itertools
import os

import pytest

Expand All @@ -18,24 +19,28 @@
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():
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()
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()


@pytest.fixture(scope="function")
Expand Down

0 comments on commit 304862c

Please sign in to comment.