def test_basic_log(self, capsys): logger = Loggable("loggable_test") logger.set_level("INFO") logger.timeit("INFO").info("log2") log, _ = capsys.readouterr() assert "INFO" in log
def test_prefix(self, capsys): log = Loggable("loggable_test") log.set_level("INFO") timeit = log.timeit(logging.INFO, "prefix") timeit.enter() timeit.info("Some information") timeit.exit() log, _ = capsys.readouterr() print(log) assert "prefix" in log
def test_spawn(self, capsys): log = Loggable("loggable_test") log.set_level("INFO") log2 = log.timeit(logging.INFO) log2.enter() log2.info("log2") log2.exit() msg, _ = capsys.readouterr() assert "started" in msg.lower() assert "log2" in msg assert "finished" in msg.lower()
def test_does_not_log(self, capsys): log = Loggable("loggable_test") log.set_level("ERROR") timeit = log.timeit(logging.INFO) timeit.enter() timeit.info("ok") time.sleep(0.1) timeit.exit() log, _ = capsys.readouterr() print(log) assert not log
def test_timeit(self, capsys): log = Loggable("loggable_test") log.set_level("INFO") timeit = log.timeit(logging.INFO) timeit.enter() timeit.info("ok") time.sleep(0.1) timeit.exit() log, _ = capsys.readouterr() print(log) assert "started" in log.lower() assert "ok" in log assert "finished" in log.lower()
def test_exception_is_raised_for_timeit(self): logger = Loggable("test loggable") with pytest.raises(ValueError) as e: with logger.timeit("ERROR"): raise ValueError
def test_timeit(self): log = Loggable("loggable_test") log.set_level("INFO") with log.timeit(logging.INFO, "TimeItTest"): log.info("ok")