Skip to content

Commit faa4e97

Browse files
committed
Fix issues with caplog in full local run
1 parent 2af6198 commit faa4e97

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

tests/run_tests/driver_mvi_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from __future__ import annotations
1212

13+
import contextlib
1314
import logging
1415
from pathlib import Path
1516

@@ -80,6 +81,7 @@ def test_magnetic_vector_run(
8081
tmp_path: Path,
8182
caplog,
8283
max_iterations=3,
84+
upper_bound=2e-3,
8385
pytest=True,
8486
):
8587
workpath = tmp_path / "inversion_test.ui.geoh5"
@@ -96,7 +98,7 @@ def test_magnetic_vector_run(
9698
mesh = geoh5.get_entity("mesh")[0]
9799
topography = geoh5.get_entity("topography")[0]
98100
inducing_field = (50000.0, 90.0, 0.0)
99-
upper_bound = 2e-3
101+
100102
dip, direction = mesh.add_data(
101103
{
102104
"dip": {"values": np.zeros(mesh.n_cells)},
@@ -111,7 +113,7 @@ def test_magnetic_vector_run(
111113
)
112114

113115
# Run the inverse
114-
with caplog.at_level(logging.WARNING):
116+
with caplog.at_level(logging.WARNING) if caplog else contextlib.nullcontext():
115117
params = MVIInversionOptions.build(
116118
geoh5=geoh5,
117119
mesh=mesh,
@@ -135,8 +137,8 @@ def test_magnetic_vector_run(
135137
initial_beta_ratio=1e1,
136138
)
137139
params.write_ui_json(path=tmp_path / "Inv_run.ui.json")
138-
139-
assert "Skipping deprecated field: lower_bound" in caplog.text
140+
if caplog:
141+
assert "Skipping deprecated field: lower_bound" in caplog.text
140142

141143
driver = MVIInversionDriver(params)
142144
assert np.all(driver.models.lower_bound == -upper_bound)
@@ -172,4 +174,6 @@ def test_magnetic_vector_run(
172174
if __name__ == "__main__":
173175
# Full run
174176
test_magnetic_vector_fwr_run(Path("./"), n_grid_points=20, refinement=(4, 8))
175-
test_magnetic_vector_run(Path("./"), "", max_iterations=30, pytest=False)
177+
test_magnetic_vector_run(
178+
Path("./"), None, max_iterations=30, upper_bound=1e-1, pytest=False
179+
)

0 commit comments

Comments
 (0)