Skip to content

Refactoring tests utils #1109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c4b5f03
Moved testutils to tests dir
gavin-aguiar Sep 7, 2022
8151742
Added logs
gavin-aguiar Sep 7, 2022
988552b
Relative import
gavin-aguiar Sep 7, 2022
dfeb622
Changed to absolute import
gavin-aguiar Sep 8, 2022
574e2e3
Testing change
gavin-aguiar Sep 8, 2022
7eca490
Removed init
gavin-aguiar Sep 8, 2022
16949d9
Added -m
gavin-aguiar Sep 9, 2022
dc2ea52
Removed -m
gavin-aguiar Sep 9, 2022
1688e6c
Updated setup to install utils
gavin-aguiar Sep 15, 2022
7cf90c2
Updated setup.py to include tests
gavin-aguiar Sep 21, 2022
d6b984a
Trying relative imports
gavin-aguiar Sep 21, 2022
6fafda7
Skipping flaky test
gavin-aguiar Sep 30, 2022
f7a447b
Pinning fastapi version
gavin-aguiar Sep 30, 2022
3622014
Skipped SQL tests
gavin-aguiar Oct 3, 2022
e05b4ec
fixing flake8 tests
gavin-aguiar Oct 3, 2022
7a8939e
Fixed linux con tests
gavin-aguiar Oct 3, 2022
16bc224
Addressed comments
gavin-aguiar Oct 7, 2022
1d520a1
Removed 310 tests for dep iso
gavin-aguiar Oct 10, 2022
3f7ecfc
Fixed flake8 tests
gavin-aguiar Oct 10, 2022
982075c
Resolved conflicts
gavin-aguiar Oct 11, 2022
f9cbc0e
Merge branch 'dev' into gaaguiar/move_test_utils
vrdmr Oct 12, 2022
d2a5dc0
Merge branch 'dev' into gaaguiar/move_test_utils
vrdmr Oct 18, 2022
e08ecb1
Merge branch 'dev' into gaaguiar/move_test_utils
vrdmr Oct 18, 2022
6ae6741
Merge branch 'dev' into gaaguiar/move_test_utils
Oct 19, 2022
e0e6bcd
Resolving conflicts
Oct 20, 2022
bdf4f7a
Flake8 fix
Oct 20, 2022
8af8143
Merge branch 'dev' into gaaguiar/move_test_utils
gavin-aguiar Oct 24, 2022
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
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
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