Beispiel #1
0
def test_custom_loglevel_and_file(tmpdir):
    """Test if custom logging settings are effective."""
    wd = WorkDir(tmpdir, logfile="mylog.txt", loglevel_file=logging.INFO)
    wd.log("Hello", logging.DEBUG)
    wd.log("Bye", logging.WARN)
    assert os.path.isfile(tmpdir / "mylog.txt")
    with open(tmpdir / "mylog.txt") as f:
        lines = f.readlines()
        assert "Bye" in lines[0]
Beispiel #2
0
def test_log_errors(tmpdir):
    """Test if errors are written to the logfile."""
    wd = WorkDir(tmpdir, logfile="mylog.txt", loglevel_file=logging.INFO)
    wd.log("Hello", logging.DEBUG)
    with pytest.raises(AssertionError):
        with wd:
            assert False
    with open(tmpdir / "mylog.txt") as f:
        assert "AssertionError" in f.read()
Beispiel #3
0
def test_logging(tmpdir):
    """Test logging with default configuration."""
    wd = WorkDir(tmpdir)
    assert wd.logger is None
    assert not os.path.isfile(tmpdir / "workdir.log")
    wd.log("Hi")
    # File is created with first log
    assert os.path.isfile(tmpdir / "workdir.log")
    wd.log("Hello", logging.DEBUG)
    wd.log("Bye", logging.WARN)
    with open(tmpdir / "workdir.log") as f:
        lines = f.readlines()
        assert "Hi" in lines[0]
        assert "Hello" in lines[1]
        assert "Bye" in lines[2]