Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6e40d0

Browse files
simplify test module
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent165c4f3 commita6e40d0

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

‎examples/experimental/sea_connector_test.py‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
"""
22
Main script to run all SEA connector tests.
33
4-
This scriptimports andruns all the individual test modules and displays
4+
This script runs all the individual test modules and displays
55
a summary of test results with visual indicators.
66
"""
77
importos
88
importsys
99
importlogging
10-
importimportlib.util
11-
fromtypingimportDict,Callable,List,Tuple
10+
importsubprocess
11+
fromtypingimportList,Tuple
1212

13-
# Configure logging
1413
logging.basicConfig(level=logging.INFO)
1514
logger=logging.getLogger(__name__)
1615

17-
# Define test modules and their main test functions
1816
TEST_MODULES= [
1917
"test_sea_session",
2018
"test_sea_sync_query",
@@ -23,29 +21,27 @@
2321
]
2422

2523

26-
defload_test_function(module_name:str)->Callable:
27-
"""Load a testfunction from a module."""
24+
defrun_test_module(module_name:str)->bool:
25+
"""Run a testmodule and return success status."""
2826
module_path=os.path.join(
2927
os.path.dirname(os.path.abspath(__file__)),"tests",f"{module_name}.py"
3028
)
3129

32-
spec=importlib.util.spec_from_file_location(module_name,module_path)
33-
module=importlib.util.module_from_spec(spec)
34-
spec.loader.exec_module(module)
30+
# Simply run the module as a script - each module handles its own test execution
31+
result=subprocess.run(
32+
[sys.executable,module_path],capture_output=True,text=True
33+
)
3534

36-
# Get the main test function (assuming it starts with "test_")
37-
fornameindir(module):
38-
ifname.startswith("test_")andcallable(getattr(module,name)):
39-
# For sync and async query modules, we want the main function that runs both tests
40-
ifname==f"test_sea_{module_name.replace('test_sea_','')}_exec":
41-
returngetattr(module,name)
35+
# Log the output from the test module
36+
ifresult.stdout:
37+
forlineinresult.stdout.strip().split("\n"):
38+
logger.info(line)
4239

43-
# Fallback to the first test function found
44-
fornameindir(module):
45-
ifname.startswith("test_")andcallable(getattr(module,name)):
46-
returngetattr(module,name)
40+
ifresult.stderr:
41+
forlineinresult.stderr.strip().split("\n"):
42+
logger.error(line)
4743

48-
raiseValueError(f"No test function found in module{module_name}")
44+
returnresult.returncode==0
4945

5046

5147
defrun_tests()->List[Tuple[str,bool]]:
@@ -54,12 +50,11 @@ def run_tests() -> List[Tuple[str, bool]]:
5450

5551
formodule_nameinTEST_MODULES:
5652
try:
57-
test_func=load_test_function(module_name)
5853
logger.info(f"\n{'='*50}")
5954
logger.info(f"Running test:{module_name}")
6055
logger.info(f"{'-'*50}")
6156

62-
success=test_func()
57+
success=run_test_module(module_name)
6358
results.append((module_name,success))
6459

6560
status="✅ PASSED"ifsuccesselse"❌ FAILED"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp