diff --git a/tests/test_experiment.py b/tests/test_experiment.py index 03e2b8f6..905334cc 100755 --- a/tests/test_experiment.py +++ b/tests/test_experiment.py @@ -8,6 +8,7 @@ import sys from sacred.experiment import Experiment +from sacred.utils import apply_backspaces_and_linefeeds @pytest.fixture @@ -163,10 +164,7 @@ def run(a): assert ex.run(named_configs=['ncfg']).result == 10 -def test_captured_out_filter(ex): - from sacred.utils import apply_backspaces_and_linefeeds - ex.captured_out_filter = apply_backspaces_and_linefeeds - +def test_captured_out_filter(ex, capsys): @ex.main def run_print_mock_progress(): sys.stdout.write('progress 0') @@ -176,7 +174,10 @@ def run_print_mock_progress(): sys.stdout.write(str(i)) sys.stdout.flush() - assert ex.run(options={'--loglevel': 'ERROR'}).captured_out == 'progress 9' + ex.captured_out_filter = apply_backspaces_and_linefeeds + options = {'--loglevel': 'CRITICAL'} # to disable logging + with capsys.disabled(): + assert ex.run(options=options).captured_out == 'progress 9' def test_adding_option_hooks(ex): diff --git a/tests/test_run.py b/tests/test_run.py index ae24b0cf..476f1962 100755 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -10,7 +10,8 @@ from sacred.run import Run from sacred.config.config_summary import ConfigSummary -from sacred.utils import ObserverError, SacredInterrupt, TimeoutInterrupt +from sacred.utils import (ObserverError, SacredInterrupt, TimeoutInterrupt, + apply_backspaces_and_linefeeds) @pytest.fixture @@ -224,8 +225,7 @@ def test_unobserved_run_doesnt_emit(run): assert not observer.failed_event.called -def test_captured_out_filter(run): - from sacred.utils import apply_backspaces_and_linefeeds +def test_captured_out_filter(run, capsys): def print_mock_progress(): sys.stdout.write('progress 0') sys.stdout.flush() @@ -233,7 +233,9 @@ def print_mock_progress(): sys.stdout.write('\b') sys.stdout.write(str(i)) sys.stdout.flush() + run.captured_out_filter = apply_backspaces_and_linefeeds run.main_function.side_effect = print_mock_progress - run() - assert run.captured_out == 'progress 9' + with capsys.disabled(): + run() + assert run.captured_out == 'progress 9'