File size: 1,497 Bytes
ad33df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys

import pytest

from .conftest import skip_when_haystack_not_installed


@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")
@skip_when_haystack_not_installed
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")
@skip_when_haystack_not_installed
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"