Skip to content

Commit

Permalink
tests/report: Use capsys fixture to redirect stdout/stderr
Browse files Browse the repository at this point in the history
Replace custom output redirection.

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
  • Loading branch information
jvesely committed Dec 7, 2021
1 parent 78ed00f commit df2a077
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tests/composition/test_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import contextlib
import io
import sys

import numpy as np
Expand All @@ -12,29 +10,25 @@
@pytest.mark.skipif(sys.platform == 'win32', reason="<Incompatible UDF-8 formatting of rich Console output>")
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
Expand Down

0 comments on commit df2a077

Please sign in to comment.