Skip to content

Commit

Permalink
chore(ingest): remove enable_logging helper
Browse files Browse the repository at this point in the history
Pytest does this by default. No need to redo it explicitly.
  • Loading branch information
hsheth2 committed Dec 24, 2024
1 parent f4b33b5 commit 01df044
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging
import sys
from typing import Any, Dict
from unittest import mock

Expand Down Expand Up @@ -483,12 +481,6 @@ def register_mock_admin_api(request_mock: Any, override_data: dict = {}) -> None
)


def enable_logging():
# set logging to console
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)


def mock_msal_cca(*args, **kwargs):
class MsalClient:
def acquire_token_for_client(self, *args, **kwargs):
Expand Down Expand Up @@ -527,8 +519,6 @@ def default_source_config():
@freeze_time(FROZEN_TIME)
@mock.patch("msal.ConfidentialClientApplication", side_effect=mock_msal_cca)
def test_admin_only_apis(mock_msal, pytestconfig, tmp_path, mock_time, requests_mock):
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_admin_api(request_mock=requests_mock)
Expand Down Expand Up @@ -567,8 +557,6 @@ def test_admin_only_apis(mock_msal, pytestconfig, tmp_path, mock_time, requests_
def test_most_config_and_modified_since(
mock_msal, pytestconfig, tmp_path, mock_time, requests_mock
):
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_admin_api(request_mock=requests_mock)
Expand Down
63 changes: 13 additions & 50 deletions metadata-ingestion/tests/integration/powerbi/test_powerbi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import json
import logging
import re
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional, Union, cast
from unittest import mock
Expand Down Expand Up @@ -31,30 +29,21 @@
FROZEN_TIME = "2022-02-03 07:00:00"


def enable_logging():
# set logging to console
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)


class MsalClient:
call_num = 0
token: Dict[str, Any] = {
"access_token": "dummy",
}

@staticmethod
def acquire_token_for_client(*args, **kwargs):
MsalClient.call_num += 1
return MsalClient.token

@staticmethod
def reset():
MsalClient.call_num = 0
def mock_msal_cca(*args, **kwargs):
class MsalClient:
call_num = 0
token: Dict[str, Any] = {
"access_token": "dummy",
}

@staticmethod
def acquire_token_for_client(*args, **kwargs):
MsalClient.call_num += 1
return MsalClient.token

def mock_msal_cca(*args, **kwargs):
return MsalClient()
@staticmethod
def reset():
MsalClient.call_num = 0


def scan_init_response(request, context):
Expand Down Expand Up @@ -154,8 +143,6 @@ def test_powerbi_ingest(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -199,8 +186,6 @@ def test_powerbi_workspace_type_filter(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(
Expand Down Expand Up @@ -260,8 +245,6 @@ def test_powerbi_ingest_patch_disabled(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -327,8 +310,6 @@ def test_powerbi_platform_instance_ingest(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -515,8 +496,6 @@ def test_extract_reports(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -561,8 +540,6 @@ def test_extract_lineage(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -660,8 +637,6 @@ def test_admin_access_is_not_allowed(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(
Expand Down Expand Up @@ -723,8 +698,6 @@ def test_workspace_container(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)
Expand Down Expand Up @@ -772,8 +745,6 @@ def test_access_token_expiry_with_long_expiry(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)

pipeline = Pipeline.create(
Expand Down Expand Up @@ -814,8 +785,6 @@ def test_access_token_expiry_with_short_expiry(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

register_mock_api(pytestconfig=pytestconfig, request_mock=requests_mock)

pipeline = Pipeline.create(
Expand Down Expand Up @@ -940,8 +909,6 @@ def test_dataset_type_mapping_error(
def test_server_to_platform_map(
mock_msal, pytestconfig, tmp_path, mock_time, requests_mock
):
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"
new_config: dict = {
**default_source_config(),
Expand Down Expand Up @@ -1416,8 +1383,6 @@ def test_powerbi_cross_workspace_reference_info_message(
mock_time: datetime.datetime,
requests_mock: Any,
) -> None:
enable_logging()

register_mock_api(
pytestconfig=pytestconfig,
request_mock=requests_mock,
Expand Down Expand Up @@ -1495,8 +1460,6 @@ def common_app_ingest(
output_mcp_path: str,
override_config: dict = {},
) -> Pipeline:
enable_logging()

register_mock_api(
pytestconfig=pytestconfig,
request_mock=requests_mock,
Expand Down
10 changes: 0 additions & 10 deletions metadata-ingestion/tests/integration/powerbi/test_profiling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging
import sys
from typing import Any, Dict
from unittest import mock

Expand Down Expand Up @@ -271,12 +269,6 @@ def register_mock_admin_api(request_mock: Any, override_data: dict = {}) -> None
)


def enable_logging():
# set logging to console
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)


def mock_msal_cca(*args, **kwargs):
class MsalClient:
def acquire_token_for_client(self, *args, **kwargs):
Expand Down Expand Up @@ -311,8 +303,6 @@ def default_source_config():
@freeze_time(FROZEN_TIME)
@mock.patch("msal.ConfidentialClientApplication", side_effect=mock_msal_cca)
def test_profiling(mock_msal, pytestconfig, tmp_path, mock_time, requests_mock):
enable_logging()

test_resources_dir = pytestconfig.rootpath / "tests/integration/powerbi"

register_mock_admin_api(request_mock=requests_mock)
Expand Down
Loading

0 comments on commit 01df044

Please sign in to comment.