kotaemon/tests/test_telemetry.py
ian_Cin 5241edbc46 [AUR-361] Setup pre-commit, pytest, GitHub actions, ssh-secret (#3)
Co-authored-by: trducng <trungduc1992@gmail.com>
2023-08-30 07:22:01 +07:00

55 lines
1.3 KiB
Python

import os
import sys
import pytest
@pytest.fixture
def clean_artifacts_for_telemetry():
try:
del sys.modules["kotaemon"]
except KeyError:
pass
try:
del sys.modules["haystack"]
except KeyError:
pass
try:
del sys.modules["haystack.telemetry"]
except KeyError:
pass
if "HAYSTACK_TELEMETRY_ENABLED" in os.environ:
del os.environ["HAYSTACK_TELEMETRY_ENABLED"]
@pytest.mark.usefixtures("clean_artifacts_for_telemetry")
def test_disable_telemetry_import_haystack_first():
"""Test that telemetry is disabled when kotaemon lib is initiated after"""
import os
import haystack.telemetry
assert haystack.telemetry.telemetry is not None
assert os.environ.get("HAYSTACK_TELEMETRY_ENABLED", "True") != "False"
import kotaemon # noqa: F401
assert haystack.telemetry.telemetry is None
assert os.environ.get("HAYSTACK_TELEMETRY_ENABLED", "True") == "False"
@pytest.mark.usefixtures("clean_artifacts_for_telemetry")
def test_disable_telemetry_import_haystack_after_kotaemon():
"""Test that telemetry is disabled when kotaemon lib is initiated before"""
import os
import haystack.telemetry
import kotaemon # noqa: F401
assert haystack.telemetry.telemetry is None
assert os.environ.get("HAYSTACK_TELEMETRY_ENABLED", "True") == "False"