Skip to content

Commit 67b064c

Browse files
committed
fix: improve test coverage and fix flakey test
1 parent 87d2fbc commit 67b064c

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/functions_framework/aio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def create_asgi_app_from_module(target, source, signature_type, source_module, s
229229
A Starlette ASGI application instance
230230
"""
231231
enable_id_logging = _enable_execution_id_logging()
232-
if enable_id_logging:
232+
if enable_id_logging: # pragma: no cover
233233
_configure_app_execution_id_logging()
234234

235235
function = _function_registry.get_user_function(source, source_module, target)

tests/test_cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from functions_framework._cli import _cli
3030

3131

32-
@pytest.fixture
32+
@pytest.fixture(autouse=True)
3333
def clean_registries():
3434
"""Clean up both REGISTRY_MAP and ASGI_FUNCTIONS registries."""
3535
original_registry_map = _function_registry.REGISTRY_MAP.copy()
@@ -145,8 +145,12 @@ def test_asgi_cli(monkeypatch):
145145
assert asgi_server.run.calls == [pretend.call("0.0.0.0", 8080)]
146146

147147

148-
def test_cli_auto_detects_asgi_decorator(clean_registries):
148+
@pytest.mark.parametrize("log_execution_id", [None, "true"])
149+
def test_cli_auto_detects_asgi_decorator(monkeypatch, log_execution_id):
149150
"""Test that CLI auto-detects @aio decorated functions without --asgi flag."""
151+
if log_execution_id:
152+
monkeypatch.setenv("LOG_EXECUTION_ID", log_execution_id)
153+
150154
# Use the actual async_decorator.py test file which has @aio.http decorated functions
151155
test_functions_dir = pathlib.Path(__file__).parent / "test_functions" / "decorators"
152156
source = test_functions_dir / "async_decorator.py"

tests/test_decorator_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
TEST_FUNCTIONS_DIR = pathlib.Path(__file__).resolve().parent / "test_functions"
3939

4040

41-
@pytest.fixture
41+
@pytest.fixture(autouse=True)
4242
def clean_registries():
4343
"""Clean up both REGISTRY_MAP and ASGI_FUNCTIONS registries."""
4444
original_registry_map = registry.REGISTRY_MAP.copy()
@@ -147,7 +147,7 @@ def test_aio_http_dict_response():
147147
assert resp.json() == {"message": "hello", "count": 42, "success": True}
148148

149149

150-
def test_aio_decorators_register_asgi_functions(clean_registries):
150+
def test_aio_decorators_register_asgi_functions():
151151
"""Test that @aio decorators add function names to ASGI_FUNCTIONS registry."""
152152
from functions_framework.aio import cloud_event, http
153153

tests/test_function_registry.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@
1313
# limitations under the License.
1414
import os
1515

16+
import pytest
17+
1618
from functions_framework import _function_registry
1719

1820

21+
@pytest.fixture(autouse=True)
22+
def clean_registries():
23+
"""Clean up both REGISTRY_MAP and ASGI_FUNCTIONS registries."""
24+
original_registry_map = _function_registry.REGISTRY_MAP.copy()
25+
original_asgi = _function_registry.ASGI_FUNCTIONS.copy()
26+
_function_registry.REGISTRY_MAP.clear()
27+
_function_registry.ASGI_FUNCTIONS.clear()
28+
yield
29+
_function_registry.REGISTRY_MAP.clear()
30+
_function_registry.REGISTRY_MAP.update(original_registry_map)
31+
_function_registry.ASGI_FUNCTIONS.clear()
32+
_function_registry.ASGI_FUNCTIONS.update(original_asgi)
33+
34+
1935
def test_get_function_signature():
2036
test_cases = [
2137
{

0 commit comments

Comments
 (0)