1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

added test for classvar logging

This commit is contained in:
A_D 2021-05-10 15:29:04 +02:00
parent 92e580e0c7
commit 36ccead469
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -0,0 +1,44 @@
import sys
sys.path += "../" # Dont ask me why for this one it breaks, it just does.
from typing import TYPE_CHECKING # noqa: E402
from EDMCLogging import get_plugin_logger # noqa: E402
if TYPE_CHECKING:
from _pytest.logging import LogCaptureFixture
logger = get_plugin_logger('EDMCLogging.py')
class ClassVarLogger:
"""Test class with logger attached."""
@classmethod
def set_logger(cls, logger):
"""Set the passed logger onto the _class_."""
ClassVarLogger.logger = logger
def log_stuff(msg: str):
"""Wrapper logger func."""
ClassVarLogger.logger.debug(msg) # type: ignore # its there
def test_class_logger(caplog: 'LogCaptureFixture'):
"""
Test that logging from a class variable doesn't explode.
In writting a plugin that uses a class variable to hold the logger, EDMCLoggings cleverness to extract data
regarding the qualified name of a function falls flat, as a class variable does not have a qualname, and at the time
we did not check for its existence before using it.
"""
ClassVarLogger.set_logger(logger)
ClassVarLogger.logger.debug('test') # type: ignore # its there
ClassVarLogger.logger.info('test2') # type: ignore # its there
log_stuff('test3') # type: ignore # its there
# Dont move these, it relies on the line numbres.
assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:37 test' in caplog.text
assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:38 test2' in caplog.text
assert 'EDMarketConnector.EDMCLogging.py:test_logging_classvar.py:25 test3' in caplog.text