Skip to content

Commit

Permalink
Refactoring tests utils (#1109)
Browse files Browse the repository at this point in the history
* Moved testutils to tests dir

* Added logs

* Relative import

* Changed to absolute import

* Testing change

* Removed init

* Added -m

* Removed -m

* Updated setup to install utils

* Updated setup.py to include tests

* Trying relative imports

* Skipping flaky test

* Pinning fastapi version

* Skipped SQL tests

* fixing flake8 tests

* Fixed linux con tests

* Removed 310 tests for dep iso

* Fixed flake8 tests

* Resolving conflicts

* Flake8 fix

Co-authored-by: Varad Meru <[email protected]>
Co-authored-by: Gavin Aguiar <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2022
1 parent e090dcc commit 28e5fdb
Show file tree
Hide file tree
Showing 43 changed files with 97 additions and 88 deletions.
4 changes: 0 additions & 4 deletions azure_functions_worker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
# Debug Flags
PYAZURE_WEBHOST_DEBUG = "PYAZURE_WEBHOST_DEBUG"

# E2E Integration Flags and Configurations
PYAZURE_INTEGRATION_TEST = "PYAZURE_INTEGRATION_TEST"
PYAZURE_WORKER_DIR = "PYAZURE_WORKER_DIR"

# Platform Environment Variables
AZURE_WEBJOBS_SCRIPT_ROOT = "AzureWebJobsScriptRoot"
CONTAINER_NAME = "CONTAINER_NAME"
Expand Down
2 changes: 0 additions & 2 deletions tests/common/ping/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions tests/common/ping/function.json

This file was deleted.

2 changes: 1 addition & 1 deletion tests/endtoend/test_blob_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.
import time

from azure_functions_worker import testutils
from tests.utils import testutils


class TestBlobFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_blueprint_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from azure_functions_worker import testutils
from tests.utils import testutils


class TestFunctionInBluePrintOnly(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_cosmosdb_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import time

from azure_functions_worker import testutils
from tests.utils import testutils


class TestCosmosDBFunctions(testutils.WebHostTestCase):
Expand Down
7 changes: 4 additions & 3 deletions tests/endtoend/test_dependency_isolation_functions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import os
import importlib.util
import os
from unittest import skip
from unittest.case import skipIf
from unittest.mock import patch

from requests import Response
from azure_functions_worker import testutils

from azure_functions_worker.utils.common import is_envvar_true
from azure_functions_worker.constants import PYAZURE_INTEGRATION_TEST
from tests.utils import testutils
from tests.utils.constants import PYAZURE_INTEGRATION_TEST

REQUEST_TIMEOUT_SEC = 5

Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_durable_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_functions_worker import testutils
from tests.utils import testutils


class TestDurableFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_eventgrid_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import requests

from azure_functions_worker import testutils
from tests.utils import testutils


class TestEventGridFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_eventhub_batch_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime
from dateutil import parser, tz

from azure_functions_worker import testutils
from tests.utils import testutils


class TestEventHubFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_eventhub_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dateutil import parser, tz

from azure_functions_worker import testutils
from tests.utils import testutils


class TestEventHubFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_http_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import requests

from azure_functions_worker import testutils
from tests.utils import testutils

REQUEST_TIMEOUT_SEC = 5

Expand Down
4 changes: 2 additions & 2 deletions tests/endtoend/test_linux_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Licensed under the MIT License.
import os
import sys

from unittest import TestCase, skipIf

from requests import Request

from azure_functions_worker.testutils_lc import (
from tests.utils.testutils_lc import (
LinuxConsumptionWebHostController
)

Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_queue_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.
import time

from azure_functions_worker import testutils
from tests.utils import testutils


class TestQueueFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_servicebus_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import time

from azure_functions_worker import testutils
from tests.utils import testutils


class TestServiceBusFunctions(testutils.WebHostTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_sql_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from unittest import skip

from azure_functions_worker import testutils
from tests.utils import testutils


@skip("Unskip when azure functions with SQL is released.")
Expand Down
2 changes: 1 addition & 1 deletion tests/endtoend/test_table_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib
import time

from azure_functions_worker import testutils
from tests.utils import testutils


class TestTableFunctions(testutils.WebHostTestCase):
Expand Down
10 changes: 3 additions & 7 deletions tests/endtoend/test_third_party_http_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
from unittest.mock import patch

import requests

from azure_functions_worker import testutils as utils, testutils

# from tests.stein_tests import testutils
# from tests.stein_tests.constants import E2E_TESTS_ROOT
from azure_functions_worker.testutils import E2E_TESTS_ROOT
from tests.utils import testutils as utils
from tests.utils.testutils import E2E_TESTS_ROOT

HOST_JSON_TEMPLATE = """\
{
Expand All @@ -33,7 +29,7 @@ class ThirdPartyHttpFunctionsTestBase:
"""Base test class containing common asgi/wsgi testcases, only testcases
in classes extending TestThirdPartyHttpFunctions will by run"""

class TestThirdPartyHttpFunctions(testutils.WebHostTestCase):
class TestThirdPartyHttpFunctions(utils.WebHostTestCase):
@classmethod
def setUpClass(cls):
host_json = cls.get_script_dir() / 'host.json'
Expand Down
11 changes: 6 additions & 5 deletions tests/unittests/azure_namespace_import/azure_namespace_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import shutil
import asyncio

from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from ...utils.testutils import create_dummy_dispatcher, UNIT_TESTS_ROOT


async def vertify_nested_namespace_import():
async def verify_nested_namespace_import():
test_env = {}
request = protos.FunctionEnvironmentReloadRequest(
environment_variables=test_env)
Expand All @@ -17,14 +18,14 @@ async def vertify_nested_namespace_import():
request_id='0',
function_environment_reload_request=request)

disp = testutils.create_dummy_dispatcher()
disp = create_dummy_dispatcher()

# Mock intepreter starts in placeholder mode
import azure.module_a as mod_a # noqa: F401

# Mock function specialization, load customer's libraries and functionapps
ns_root = os.path.join(
testutils.UNIT_TESTS_ROOT,
UNIT_TESTS_ROOT,
'azure_namespace_import',
'namespace_location_b')
test_path = os.path.join(ns_root, 'azure', 'namespace_b', 'module_b')
Expand All @@ -50,5 +51,5 @@ async def vertify_nested_namespace_import():

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(vertify_nested_namespace_import())
loop.run_until_complete(verify_nested_namespace_import())
loop.close()
3 changes: 2 additions & 1 deletion tests/unittests/path_import/path_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import shutil
import asyncio

from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


async def verify_path_imports():
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_broken_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


class TestMockHost(testutils.AsyncTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from typing import Optional, Tuple
from unittest.mock import patch

from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils
from azure_functions_worker.constants import PYTHON_THREADPOOL_THREAD_COUNT, \
PYTHON_THREADPOOL_THREAD_COUNT_DEFAULT, \
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37, PYTHON_THREADPOOL_THREAD_COUNT_MIN
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_enable_debug_logging_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
from unittest.mock import patch

from azure_functions_worker import testutils
from tests.utils import testutils
from azure_functions_worker.constants import PYTHON_ENABLE_DEBUG_LOGGING
from azure_functions_worker.testutils import TESTS_ROOT, remove_path
from tests.utils.testutils import TESTS_ROOT, remove_path

HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO = """\
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_file_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest
from unittest import skipIf

from azure_functions_worker import testutils
from tests.utils import testutils
from azure_functions_worker.bindings.shared_memory_data_transfer \
import SharedMemoryException

Expand Down
5 changes: 2 additions & 3 deletions tests/unittests/test_http_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import pytest

from azure_functions_worker import testutils
from azure_functions_worker.testutils import WebHostTestCase
from tests.utils import testutils


class TestHttpFunctions(WebHostTestCase):
class TestHttpFunctions(testutils.WebHostTestCase):

@classmethod
def get_script_dir(cls):
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import textwrap

from azure_functions_worker import testutils
from tests.utils import testutils


class TestLoader(testutils.WebHostTestCase):
Expand Down Expand Up @@ -150,7 +150,7 @@ async def test_entry_point_plugin(self):
code = textwrap.dedent('''
import asyncio
from azure_functions_worker import protos
from azure_functions_worker import testutils
from tests.utils import testutils
async def _runner():
async with testutils.start_mockhost(
Expand Down
9 changes: 4 additions & 5 deletions tests/unittests/test_log_filtering_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# Licensed under the MIT License.
import typing

from azure_functions_worker import testutils
from azure_functions_worker.testutils import TESTS_ROOT, remove_path
from tests.utils import testutils

HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO = """\
{
Expand Down Expand Up @@ -31,7 +30,7 @@ class TestLogFilteringFunctions(testutils.WebHostTestCase):

@classmethod
def setUpClass(cls):
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json'
host_json = testutils.TESTS_ROOT / cls.get_script_dir() / 'host.json'

with open(host_json, 'w+') as f:
f.write(HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO)
Expand All @@ -40,8 +39,8 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json'
remove_path(host_json)
host_json = testutils.TESTS_ROOT / cls.get_script_dir() / 'host.json'
testutils.remove_path(host_json)

super(TestLogFilteringFunctions, cls).tearDownClass()

Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_blob_shared_memory_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import SharedMemoryMap
from azure_functions_worker.bindings.shared_memory_data_transfer \
import SharedMemoryConstants as consts
from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


@skipIf(sys.platform == 'darwin', 'MacOS M1 machines do not correctly test the'
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_durable_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


class TestDurableFunctions(testutils.AsyncTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_eventhub_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Licensed under the MIT License.
import json

from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


class TestEventHubMockFunctions(testutils.AsyncTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_generic_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


class TestGenericFunctions(testutils.AsyncTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_http_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils


class TestMockHost(testutils.AsyncTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unittests/test_mock_log_filtering_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Licensed under the MIT License.
from unittest.mock import patch, call

from azure_functions_worker import protos, testutils
from azure_functions_worker import protos
from tests.utils import testutils
from azure_functions_worker.logging import is_system_log_category


Expand Down
Loading

0 comments on commit 28e5fdb

Please sign in to comment.