Skip to content

Commit 01e323f

Browse files
Fix abipy test runner inconsistency (#1319)
* make abinit config dir before imported * update abipy monkeypatching
1 parent c8941c2 commit 01e323f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

tests/abinit/conftest.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
_ABINIT_FILES = ("run.abi", "abinit_input.json")
2121
_FAKE_RUN_ABINIT_KWARGS = {}
2222

23+
# Do this here to prevent issues with threaded CI runners
24+
# In abipy, it's possible to have thread collisions in
25+
# making this directory because `exist_ok = False` there
26+
_ABINIT_PATH = Path("~/.abinit").expanduser()
27+
if not _ABINIT_PATH.is_dir():
28+
_ABINIT_PATH.mkdir(exist_ok=True, parents=True)
29+
2330

2431
@pytest.fixture(scope="session")
2532
def abinit_test_dir(test_dir):
@@ -32,7 +39,7 @@ def abinit_integration_tests(pytestconfig):
3239

3340

3441
@pytest.fixture
35-
def mock_abinit(mocker, abinit_test_dir, abinit_integration_tests):
42+
def mock_abinit(monkeypatch, abinit_test_dir, abinit_integration_tests):
3643
"""
3744
This fixture allows one to mock running ABINIT.
3845
@@ -56,7 +63,7 @@ def wrapped_write_abinit_input_set(*args, **kwargs):
5663
atomate2.abinit.files.write_abinit_input_set(*args, **kwargs)
5764
check_abinit_inputs(ref_path)
5865

59-
mocker.patch.object(
66+
monkeypatch.setattr(
6067
atomate2.abinit.jobs.base,
6168
"write_abinit_input_set",
6269
wrapped_write_abinit_input_set,
@@ -73,8 +80,8 @@ def mock_run_abinit(wall_time=None, start_time=None):
7380
check_abinit_inputs(ref_path)
7481
fake_run_abinit(ref_path)
7582

76-
mocker.patch.object(atomate2.abinit.run, "run_abinit", mock_run_abinit)
77-
mocker.patch.object(atomate2.abinit.jobs.base, "run_abinit", mock_run_abinit)
83+
monkeypatch.setattr(atomate2.abinit.run, "run_abinit", mock_run_abinit)
84+
monkeypatch.setattr(atomate2.abinit.jobs.base, "run_abinit", mock_run_abinit)
7885

7986
def _run(ref_paths, fake_run_abinit_kwargs=None):
8087
if fake_run_abinit_kwargs is None:
@@ -84,7 +91,7 @@ def _run(ref_paths, fake_run_abinit_kwargs=None):
8491

8592
yield _run
8693

87-
mocker.stopall()
94+
monkeypatch.undo()
8895
_REF_PATHS.clear()
8996
_FAKE_RUN_ABINIT_KWARGS.clear()
9097

tests/abinit/sets/test_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_generator_resolve_deps():
316316
assert len(input_files) == 2
317317

318318

319-
def test_generator_get_input_set(si_structure, mocker):
319+
def test_generator_get_input_set(si_structure, monkeypatch):
320320
with ScratchDir(".") as tmpdir:
321321
saisg = SomeAbinitInputSetGenerator(factory=mocked_factory)
322322
abinit_input_set = saisg.get_input_set(
@@ -336,10 +336,10 @@ def test_generator_get_input_set(si_structure, mocker):
336336
out_den1b = Path(os.path.join(output1b, OUTDIR_NAME, "out_DEN"))
337337
out_den1b.touch()
338338

339-
mocker.patch.object(
339+
monkeypatch.setattr(
340340
atomate2.abinit.sets.base,
341341
"get_final_structure",
342-
return_value=si_structure,
342+
value=lambda x: si_structure, # noqa : ARG005
343343
)
344344
abinit_input_set = saisg.get_input_set(
345345
structure=si_structure,

0 commit comments

Comments
 (0)