mirror of https://github.com/langgenius/dify.git
fix: skip tests if no database run (#28102)
Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
parent
81832c14ee
commit
a39b50adbb
|
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Utilities for detecting if database service is available for workflow tests.
|
||||
"""
|
||||
|
||||
import psycopg2
|
||||
import pytest
|
||||
|
||||
from configs import dify_config
|
||||
|
||||
|
||||
def is_database_available() -> bool:
|
||||
"""
|
||||
Check if the database service is available by attempting to connect to it.
|
||||
|
||||
Returns:
|
||||
True if database is available, False otherwise.
|
||||
"""
|
||||
try:
|
||||
# Try to establish a database connection using a context manager
|
||||
with psycopg2.connect(
|
||||
host=dify_config.DB_HOST,
|
||||
port=dify_config.DB_PORT,
|
||||
database=dify_config.DB_DATABASE,
|
||||
user=dify_config.DB_USERNAME,
|
||||
password=dify_config.DB_PASSWORD,
|
||||
connect_timeout=2, # 2 second timeout
|
||||
) as conn:
|
||||
pass # Connection established and will be closed automatically
|
||||
return True
|
||||
except (psycopg2.OperationalError, psycopg2.Error):
|
||||
return False
|
||||
|
||||
|
||||
def skip_if_database_unavailable():
|
||||
"""
|
||||
Pytest skip decorator that skips tests when database service is unavailable.
|
||||
|
||||
Usage:
|
||||
@skip_if_database_unavailable()
|
||||
def test_my_workflow():
|
||||
...
|
||||
"""
|
||||
return pytest.mark.skipif(
|
||||
not is_database_available(),
|
||||
reason="Database service is not available (connection refused or authentication failed)",
|
||||
)
|
||||
|
|
@ -6,9 +6,11 @@ This module tests the iteration node's ability to:
|
|||
2. Preserve nested array structure when flatten_output=False
|
||||
"""
|
||||
|
||||
from .test_database_utils import skip_if_database_unavailable
|
||||
from .test_table_runner import TableTestRunner, WorkflowTestCase
|
||||
|
||||
|
||||
@skip_if_database_unavailable()
|
||||
def test_iteration_with_flatten_output_enabled():
|
||||
"""
|
||||
Test iteration node with flatten_output=True (default behavior).
|
||||
|
|
@ -37,6 +39,7 @@ def test_iteration_with_flatten_output_enabled():
|
|||
)
|
||||
|
||||
|
||||
@skip_if_database_unavailable()
|
||||
def test_iteration_with_flatten_output_disabled():
|
||||
"""
|
||||
Test iteration node with flatten_output=False.
|
||||
|
|
@ -65,6 +68,7 @@ def test_iteration_with_flatten_output_disabled():
|
|||
)
|
||||
|
||||
|
||||
@skip_if_database_unavailable()
|
||||
def test_iteration_flatten_output_comparison():
|
||||
"""
|
||||
Run both flatten_output configurations in parallel to verify the difference.
|
||||
|
|
|
|||
Loading…
Reference in New Issue