Skip to content

Commit 659820c

Browse files
committed
fix: change stdout capture strategy
1 parent f31bcc6 commit 659820c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

templateflow/conf/tests/test_conf.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _find_message(lines, msg, reverse=True):
3939

4040

4141
@pytest.mark.parametrize('use_datalad', ['off', 'on'])
42-
def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad):
42+
def test_conf_init(monkeypatch, tmp_path, use_datalad):
4343
"""Check the correct functioning of config set-up."""
4444
home = (tmp_path / f'conf-init-{use_datalad}').resolve()
4545
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', use_datalad)
@@ -56,25 +56,26 @@ def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad):
5656

5757

5858
@pytest.mark.parametrize('use_datalad', ['off', 'on'])
59-
def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
59+
def test_setup_home(monkeypatch, tmp_path, capfd, use_datalad):
6060
"""Check the correct functioning of the installation hook."""
6161
home = (tmp_path / f'setup-home-{use_datalad}').resolve()
6262
monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', use_datalad)
6363
monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
6464

65-
reload(tfc)
65+
with capfd.disabled():
66+
reload(tfc)
6667
# First execution, the S3 stub is created (or datalad install)
6768
assert tfc.TF_CACHED is False
6869
assert tfc.setup_home() is False
6970

70-
out = capsys.readouterr().out
71+
out = capfd.readouterr().out
7172
assert _find_message(out, 'TemplateFlow was not cached')
7273
assert ('TEMPLATEFLOW_HOME=%s' % home) in out
7374
assert home.exists()
7475
assert len(list(home.iterdir())) > 0
7576

7677
updated = tfc.setup_home(force=True) # Templateflow is now cached
77-
out = capsys.readouterr()[0]
78+
out = capfd.readouterr()[0]
7879
assert _find_message(out, 'TemplateFlow was not cached') is False
7980

8081
if use_datalad == 'on':
@@ -89,14 +90,14 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
8990
# Let's force an update
9091
rmtree(str(home / 'tpl-MNI152NLin2009cAsym'))
9192
updated = tfc.setup_home(force=True)
92-
out = capsys.readouterr()[0]
93+
out = capfd.readouterr()[0]
9394
assert updated is True
9495
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.')
9596

9697
reload(tfc)
9798
assert tfc.TF_CACHED is True
9899
updated = tfc.setup_home() # Templateflow is now cached
99-
out = capsys.readouterr()[0]
100+
out = capfd.readouterr()[0]
100101
assert not _find_message(out, 'TemplateFlow was not cached')
101102

102103
if use_datalad == 'on':
@@ -111,7 +112,7 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
111112
# Let's force an update
112113
rmtree(str(home / 'tpl-MNI152NLin2009cAsym'))
113114
updated = tfc.setup_home()
114-
out = capsys.readouterr()[0]
115+
out = capfd.readouterr()[0]
115116
assert updated is True
116117
assert _find_message(out, 'Updating TEMPLATEFLOW_HOME using S3.')
117118

0 commit comments

Comments
 (0)