Ejemplo n.º 1
0
def test_explicit_timer(capsys):
    """Test that timed section prints timing information"""
    t = Timer(TIME_MESSAGE, logger=print)
    t.start()
    sum(n**2 for n in range(1000))
    t.end()
    stdout, stderr = capsys.readouterr()
    assert RE_TIME_MESSAGE.match(stdout)
    assert stdout.count("\n") == 1
    assert stderr == ""
Ejemplo n.º 2
0
def test_error_if_timer_not_running():
    """Test that timer raises error if it is stopped before started"""
    t = Timer(TIME_MESSAGE, logger=print)
    with pytest.raises(exceptions.TimerNotRunning):
        t.end()