Skip to content

Commit 144fbfc

Browse files
committed
BF(TST): use caplog instead of capfd for testing if we log a warning
for some reason on my laptop capfd failed to provide desired effect. May be because I am running pytest with -s ;) will not investigate -- using caplog is the more kosher way for this purpose, and allows for control of the logging level we would like to have to ensure that the message is output
1 parent 8d85f14 commit 144fbfc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

heudiconv/tests/test_convert.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ def test_update_uncombined_name():
8585
assert out_fn_test == out_fn_true
8686

8787

88-
def test_b0dwi_for_fmap(tmpdir, capfd):
88+
def test_b0dwi_for_fmap(tmpdir, caplog):
8989
"""Make sure we raise a warning when .bvec and .bval files
9090
are present but the modality is not dwi.
9191
We check it by extracting a few DICOMs from a series with
9292
bvals: 5 5 1500
9393
"""
94+
import logging
95+
caplog.set_level(logging.WARNING)
9496
tmppath = tmpdir.strpath
9597
subID = 'b0dwiForFmap'
9698
args = (
@@ -101,9 +103,8 @@ def test_b0dwi_for_fmap(tmpdir, capfd):
101103

102104
# assert that it raised a warning that the fmap directory will contain
103105
# bvec and bval files.
104-
output = capfd.readouterr().err.split('\n')
105106
expected_msg = DW_IMAGE_IN_FMAP_FOLDER_WARNING.format(folder=op.join(tmppath, 'sub-%s', 'fmap') % subID)
106-
assert [o for o in output if expected_msg in o]
107+
assert any(expected_msg in c.message for c in caplog.records)
107108

108109
# check that both 'fmap' and 'dwi' directories have been extracted and they contain
109110
# *.bvec and a *.bval files

0 commit comments

Comments
 (0)