Skip to content

Commit

Permalink
Only remove logging file if permission allows it
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Feb 3, 2024
1 parent dd2099d commit a3d75e4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/tools/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging
import os

import pytest

from edisgo.tools.logger import setup_logger


Expand All @@ -13,10 +11,16 @@ def check_file_output(filename, output):
assert last_line == output


def reset_loggers():
def reset_loggers(filename):
logger = logging.getLogger("edisgo")
logger.handlers.clear()
logger.propagate = True
# try removing file - when run on github for Windows removing the file leads
# to a PermissionError
try:
os.remove(filename)
except PermissionError:
pass


class TestClass:
Expand Down Expand Up @@ -44,10 +48,9 @@ def test_setup_logger(self):
logging.debug("root")
check_file_output(filename, "root - DEBUG: root\n")

reset_loggers()
os.remove(filename)
reset_loggers(filename)

@pytest.mark.runonlinux
# @pytest.mark.runonlinux
def test_setup_logger_2(self):
"""
This test is only run on linux, as the log file is written to the user
Expand Down Expand Up @@ -77,5 +80,4 @@ def test_setup_logger_2(self):
logging.debug("root")
check_file_output(filename, "edisgo - DEBUG: edisgo\n")

reset_loggers()
os.remove(filename)
reset_loggers(filename)

0 comments on commit a3d75e4

Please sign in to comment.