import pytest from tadas.platform import logging as logging_utils @pytest.mark.parametrize( "file, expected", [ pytest.param( "test_logging_utils.py", "test_logging_utils.py", id='passed file name without path'), pytest.param( "/Users/user/tadas-etl/backend/tadas_run_today_isrc.py", "backend.tadas_run_today_isrc", id='path is in user home'), pytest.param( "/app/tadas-etl/backend/tadas_run_today_isrc.py", "backend.tadas_run_today_isrc", id='path is on server'), pytest.param( "/apps/some/backend/tadas_run_today_isrc.py", "tadas_run_today_isrc.py", id='path is not in sys.path should use file name'), pytest.param( "backend.tadas_run_today_isrc", "backend.tadas_run_today_isrc", id='passed __name__ instead of __file__ should use name'), ] ) def test_get_script_logger(file, expected, monkeypatch): monkeypatch.setattr(logging_utils.sys, 'path', ['/app/tadas-etl', '/Users/user/tadas-etl']) logger = logging_utils.get_file_logger(file=file) assert logger.name == expected