Skip to content

Commit e8f5f02

Browse files
committed
🧪 Assert shell warning via node logs (#120)
Use the node log records instead of pytest log capture for this assertion. The warning is still emitted, but it no longer reliably appears in captured log records with the recent AiiDA logging changes.
1 parent 83b4fa0 commit e8f5f02

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

tests/calculations/test_shell.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
from aiida.common.datastructures import CodeInfo
88
from aiida.engine import run_get_node
9-
from aiida.orm import Data, Float, FolderData, Int, List, RemoteData, SinglefileData, Str
9+
from aiida.orm import Data, Float, FolderData, Int, List, Log, RemoteData, SinglefileData, Str
1010

1111
from aiida_shell.calculations.shell import ShellJob
1212
from aiida_shell.data import EntryPointData, PickledData
@@ -453,7 +453,7 @@ def parser(dirpath):
453453
assert node.outputs.string == value
454454

455455

456-
def test_input_output_filename_overlap(generate_calc_job, generate_code, tmp_path, caplog):
456+
def test_input_output_filename_overlap(generate_calc_job, generate_code, tmp_path):
457457
"""Test functionality when input and output filenames overlap."""
458458
code = generate_code()
459459

@@ -481,18 +481,22 @@ def test_input_output_filename_overlap(generate_calc_job, generate_code, tmp_pat
481481

482482
# If the filename clash is due to an "implicit" filename, instead of raising, the filename of the node should be
483483
# automatically made unique and a warning logged to make the user aware.
484-
dirpath, calc_info = generate_calc_job(
485-
'core.shell',
486-
inputs={
484+
def generate_inputs():
485+
return {
487486
'code': code,
488487
'nodes': {'file': SinglefileData.from_string('content', filename='stdout')},
489-
},
490-
)
488+
}
489+
490+
dirpath, calc_info = generate_calc_job('core.shell', inputs=generate_inputs())
491+
process = generate_calc_job('core.shell', inputs=generate_inputs(), return_process=True)
492+
491493
code_info = calc_info.codes_info[0]
492494
filenames = [p.name for p in dirpath.iterdir()]
493495
assert code_info.stdout_name not in filenames
494496
assert code_info.stderr_name not in filenames
495-
assert 'filename `stdout` for node `file` overlaps' in caplog.records[0].message
497+
498+
message = 'filename `stdout` for node `file` overlaps'
499+
assert any(message in entry.message for entry in Log.collection.get_logs_for(process.node))
496500

497501
# If the contents of a ``FolderData`` overlap with a reserved filename, an exception is raised. This is done because
498502
# not doing everything will most likely fail the calculation as some input files will be overwritten. The plugin can

0 commit comments

Comments
 (0)