Skip to content

Commit ac937ca

Browse files
committed
addresses linting issues
1 parent 3c3237f commit ac937ca

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

tests/unit/conftest.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""Unit-test conftest: install lightweight stubs for Azure Functions packages.
2+
3+
``azure-functions`` and ``azure-durable-functions`` are Azure Functions
4+
runtime packages that are not installed in the library's dev dependencies —
5+
they're only needed when *running* the function app, not when testing the
6+
helper logic inside it. This conftest inserts minimal stubs into
7+
``sys.modules`` before any test module is imported so that
8+
``tests/unit/test_changefeed.py`` (and any other test that imports from
9+
``azure_functions/``) can be collected without the runtime packages present.
10+
"""
11+
12+
import sys
13+
import types
14+
15+
16+
def _install_azure_functions_stubs() -> None:
17+
# Inject stub sub-modules directly into sys.modules. Do NOT create or
18+
# overwrite the top-level ``azure`` entry — that is a real namespace
19+
# package provided by azure-cosmos (a core dependency), and replacing it
20+
# with a plain module breaks its sub-package imports.
21+
22+
# ----- azure.functions -----
23+
if "azure.functions" not in sys.modules:
24+
af = types.ModuleType("azure.functions")
25+
26+
class _AuthLevel:
27+
FUNCTION = "function"
28+
29+
af.AuthLevel = _AuthLevel
30+
af.DocumentList = list
31+
af.HttpRequest = object
32+
af.HttpResponse = object
33+
sys.modules["azure.functions"] = af
34+
35+
# ----- azure.durable_functions -----
36+
if "azure.durable_functions" not in sys.modules:
37+
adf = types.ModuleType("azure.durable_functions")
38+
39+
class _Noop:
40+
"""A do-nothing stand-in for DFApp / Blueprint decorators."""
41+
42+
def __init__(self, *args, **kwargs):
43+
pass
44+
45+
def register_functions(self, *args, **kwargs):
46+
pass
47+
48+
def route(self, *args, **kwargs):
49+
return lambda fn: fn
50+
51+
def durable_client_input(self, *args, **kwargs):
52+
return lambda fn: fn
53+
54+
def orchestration_trigger(self, *args, **kwargs):
55+
return lambda fn: fn
56+
57+
def cosmos_db_trigger(self, *args, **kwargs):
58+
return lambda fn: fn
59+
60+
def activity_trigger(self, *args, **kwargs):
61+
return lambda fn: fn
62+
63+
adf.Blueprint = _Noop
64+
adf.DFApp = _Noop
65+
adf.DurableOrchestrationContext = object
66+
sys.modules["azure.durable_functions"] = adf
67+
68+
69+
_install_azure_functions_stubs()

tests/unit/test_changefeed.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
from unittest.mock import AsyncMock, MagicMock, patch
5+
from unittest.mock import AsyncMock, patch
66

77
import pytest
88

@@ -11,7 +11,6 @@
1111

1212
from function_app import crosses_threshold, increment_counter_by, process_changefeed_batch
1313

14-
1514
# =====================================================================
1615
# crosses_threshold
1716
# =====================================================================

0 commit comments

Comments
 (0)