Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PQAnalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

log_file_env_var = os.getenv("PQANALYSIS_LOG_FILE")

if log_file_env_var and logging_env_var.lower() != "off":
if log_file_env_var and log_file_env_var.lower() != "off":
config.use_log_file = True

if log_file_env_var.lower() != "on" and len(log_file_env_var) > 0:
Expand Down
57 changes: 57 additions & 0 deletions tests/test_logging_env_vars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import subprocess
import sys

from pathlib import Path

import PQAnalysis

PACKAGE_ROOT = Path(PQAnalysis.__file__).resolve().parents[1]


def run_import(log_file_value):
env = os.environ.copy()
env.pop("PQANALYSIS_LOGGING_LEVEL", None)
env["PQANALYSIS_LOG_FILE"] = log_file_value
env["PYTHONPATH"] = str(PACKAGE_ROOT)

return subprocess.run(
[
sys.executable,
"-c",
"import PQAnalysis.config as config; import PQAnalysis; "
"print(config.use_log_file, config.log_file_name)",
],
cwd=PACKAGE_ROOT,
env=env,
capture_output=True,
text=True,
check=False,
)


def test_log_file_env_var_without_logging_level():
result = run_import("on")

assert result.returncode == 0, result.stderr

use_log_file, log_file_name = result.stdout.split()
assert use_log_file == "True"
assert log_file_name.startswith("PQAnalysis_")


def test_log_file_env_var_off():
result = run_import("off")

assert result.returncode == 0, result.stderr

use_log_file, log_file_name = result.stdout.split()
assert use_log_file == "False"
assert log_file_name != "off"


def test_log_file_env_var_custom_name():
result = run_import("my_custom.log")

assert result.returncode == 0, result.stderr
assert result.stdout.split() == ["True", "my_custom.log"]
Loading