From d34bff356431351766b9b1e8d578b7a8a8eeb9a4 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Fri, 3 Dec 2021 11:09:06 -0500 Subject: [PATCH] tests/report: Use capsys fixture to redirect stdout/stderr Replace custom output redirection. Signed-off-by: Jan Vesely --- tests/composition/test_report.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/composition/test_report.py b/tests/composition/test_report.py index 839aaaa3dbf..82e79dbf443 100644 --- a/tests/composition/test_report.py +++ b/tests/composition/test_report.py @@ -1,5 +1,3 @@ -import contextlib -import io import sys import numpy as np @@ -12,29 +10,25 @@ @pytest.mark.skipif(sys.platform == 'win32', reason="") class TestReport(): - def test_reportOutputPref_true(self): + def test_reportOutputPref_true(self, capsys): t = pnl.TransferMechanism() t.reportOutputPref = ReportOutput.FULL - f = io.StringIO() - with contextlib.redirect_stdout(f): - t.execute(1) - output = f.getvalue() + t.execute(1) + output = capsys.readouterr().out assert 'input: 1.0' in output assert 'output: 1.0' in output assert 'params' not in output - def test_reportOutputPref_params(self): + def test_reportOutputPref_params(self, capsys): t = pnl.TransferMechanism() t.reportOutputPref = 'params' - f = io.StringIO() - with contextlib.redirect_stdout(f): - t.execute(1, report_output=ReportOutput.FULL) - output = f.getvalue() + t.execute(1, report_output=ReportOutput.FULL) + output = capsys.readouterr().out assert 'input: 1.0' in output assert 'output: 1.0' in output