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

Commit831acbe

Browse files
author
d.kovalenko
committed
[test] sync with standard (common) code
1 parent95f16ac commit831acbe

File tree

3 files changed

+78
-33
lines changed

3 files changed

+78
-33
lines changed

‎tests/TestServices.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ def MakeRootTmpDirForGlobalResources(globalResourceID: str) -> str:
3232
# --------------------------------------------------------------------
3333
defGetCurTestTmpDir(request:pytest.FixtureRequest)->str:
3434
assertisinstance(request,pytest.FixtureRequest)
35-
return__class__.Helper__GetCurTestTmpDir(request)
35+
return__class__.Helper__GetCurTestTmpDir(request.node)
3636

3737
# --------------------------------------------------------------------
38-
defHelper__GetCurTestTmpDir(request:pytest.FixtureRequest)->str:
39-
assertisinstance(request,pytest.FixtureRequest)
38+
defHelper__GetCurTestTmpDir(function:pytest.Function)->str:
39+
assertisinstance(function,pytest.Function)
4040

4141
rootDir=TestServices.GetRootDir()
4242
rootTmpDir=TestServices.GetRootTmpDir()
4343

4444
# [2024-12-18] It is not a fact now.
4545
# assert rootTmpDir.startswith(rootDir)
4646

47-
testPath=str(request.path)
47+
testPath=str(function.path)
4848

4949
ifnottestPath.startswith(rootDir):
5050
raiseException(
@@ -55,23 +55,23 @@ def Helper__GetCurTestTmpDir(request: pytest.FixtureRequest) -> str:
5555

5656
result=os.path.join(rootTmpDir,testPath2)
5757

58-
ifrequest.node.clsisnotNone:
59-
clsName=request.node.cls.__name__
58+
iffunction.clsisnotNone:
59+
clsName=function.cls.__name__
6060
result=os.path.join(result,clsName)
6161

62-
result=os.path.join(result,request.node.name)
62+
result=os.path.join(result,function.name)
6363

6464
returnresult
6565

6666
# --------------------------------------------------------------------
67-
defCleanTestTmpDirBeforeExit(request:pytest.FixtureRequest):
68-
assertisinstance(request,pytest.FixtureRequest)
67+
defCleanTestTmpDirBeforeExit(function:pytest.Function):
68+
assertisinstance(function,pytest.Function)
6969

7070
ifTestConfigHelper.NoCleanup():
7171
logging.info("A final data cleanup is disabled.")
7272
return
7373

74-
tmpDir=__class__.GetCurTestTmpDir(request)
74+
tmpDir=__class__.Helper__GetCurTestTmpDir(function)
7575
asserttype(tmpDir)==str
7676

7777
ifnotos.path.exists(tmpDir):

‎tests/TestStartupData.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ def CalcRootTmpDir() -> str:
4343
asserttype(resultPath)==str
4444
returnresultPath
4545

46+
# --------------------------------------------------------------------
47+
defCalcRootLogDir()->str:
48+
ifTestConfigPropNames.TEST_CFG__LOG_DIRinos.environ:
49+
resultPath=os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
50+
else:
51+
rootDir=__class__.CalcRootDir()
52+
resultPath=os.path.join(rootDir,"logs")
53+
54+
asserttype(resultPath)==str
55+
returnresultPath
56+
4657
# --------------------------------------------------------------------
4758
defCalcCurrentTestWorkerSignature()->str:
4859
currentPID=os.getpid()
@@ -84,11 +95,18 @@ class TestStartupData:
8495
sm_RootTmpDataDir,sm_CurrentTestWorkerSignature
8596
)
8697

98+
sm_RootLogDir:str=TestStartupData__Helper.CalcRootLogDir()
99+
87100
# --------------------------------------------------------------------
88101
defGetRootDir()->str:
89102
asserttype(__class__.sm_RootDir)==str
90103
return__class__.sm_RootDir
91104

105+
# --------------------------------------------------------------------
106+
defGetRootLogDir()->str:
107+
asserttype(__class__.sm_RootLogDir)==str
108+
return__class__.sm_RootLogDir
109+
92110
# --------------------------------------------------------------------
93111
defGetCurrentTestWorkerSignature()->str:
94112
asserttype(__class__.sm_CurrentTestWorkerSignature)==str

‎tests/conftest.py‎

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .TestConfigPropimportTestConfigPropNames
55
from .TestStartupDataimportTestStartupData
66
from .TestGlobalCacheimportTestGlobalCache
7+
from .TestServicesimportTestServices
78

89
importpluggy
910
importpytest
@@ -18,6 +19,10 @@
1819
import_pytest.unittest
1920
import_pytest.logging
2021

22+
# /////////////////////////////////////////////////////////////////////////////
23+
24+
T_TUPLE__str_int=typing.Tuple[str,int]
25+
2126
# /////////////////////////////////////////////////////////////////////////////
2227
# TEST_PROCESS_STATS
2328

@@ -35,11 +40,11 @@ class TEST_PROCESS_STATS:
3540
cUnexpectedTests:int=0
3641
cAchtungTests:int=0
3742

38-
FailedTests=list[str,int]()
39-
XFailedTests=list[str,int]()
40-
NotXFailedTests=list[str]()
41-
WarningTests=list[str,int]()
42-
AchtungTests=list[str]()
43+
FailedTests:typing.List[T_TUPLE__str_int]=list()
44+
XFailedTests:typing.List[T_TUPLE__str_int]=list()
45+
NotXFailedTests:typing.List[str]=list()
46+
WarningTests:typing.List[T_TUPLE__str_int]=list()
47+
AchtungTests:typing.List[str]=list()
4348

4449
cTotalDuration:datetime.timedelta=datetime.timedelta()
4550

@@ -303,6 +308,15 @@ def helper__makereport__setup(
303308
return
304309

305310

311+
# ------------------------------------------------------------------------
312+
classExitStatusNames:
313+
FAILED="FAILED"
314+
PASSED="PASSED"
315+
XFAILED="XFAILED"
316+
SKIPPED="SKIPPED"
317+
UNEXPECTED="UNEXPECTED"
318+
319+
306320
# ------------------------------------------------------------------------
307321
defhelper__makereport__call(
308322
item:pytest.Function,call:pytest.CallInfo,outcome:pluggy.Result
@@ -345,28 +359,29 @@ def helper__makereport__call(
345359

346360
# --------
347361
exitStatus=None
362+
exitStatusInfo=None
348363
ifrep.outcome=="skipped":
349364
assertcall.excinfoisnotNone# research
350365
assertcall.excinfo.valueisnotNone# research
351366

352367
iftype(call.excinfo.value)==_pytest.outcomes.Skipped:# noqa: E721
353368
assertnothasattr(rep,"wasxfail")
354369

355-
exitStatus="SKIPPED"
370+
exitStatus=ExitStatusNames.SKIPPED
356371
reasonText=str(call.excinfo.value)
357372
reasonMsgTempl="SKIP REASON: {0}"
358373

359374
TEST_PROCESS_STATS.incrementSkippedTestCount()
360375

361376
eliftype(call.excinfo.value)==_pytest.outcomes.XFailed:# noqa: E721
362-
exitStatus="XFAILED"
377+
exitStatus=ExitStatusNames.XFAILED
363378
reasonText=str(call.excinfo.value)
364379
reasonMsgTempl="XFAIL REASON: {0}"
365380

366381
TEST_PROCESS_STATS.incrementXFailedTestCount(testID,item_error_msg_count)
367382

368383
else:
369-
exitStatus="XFAILED"
384+
exitStatus=ExitStatusNames.XFAILED
370385
asserthasattr(rep,"wasxfail")
371386
assertrep.wasxfailisnotNone
372387
asserttype(rep.wasxfail)==str# noqa: E721
@@ -403,7 +418,7 @@ def helper__makereport__call(
403418
assertitem_error_msg_count>0
404419
TEST_PROCESS_STATS.incrementFailedTestCount(testID,item_error_msg_count)
405420

406-
exitStatus="FAILED"
421+
exitStatus=ExitStatusNames.FAILED
407422
elifrep.outcome=="passed":
408423
assertcall.excinfoisNone
409424

@@ -423,17 +438,25 @@ def helper__makereport__call(
423438
assertnothasattr(rep,"wasxfail")
424439

425440
TEST_PROCESS_STATS.incrementPassedTestCount()
426-
exitStatus="PASSED"
441+
exitStatus=ExitStatusNames.PASSED
427442
else:
428443
TEST_PROCESS_STATS.incrementUnexpectedTests()
429-
exitStatus="UNEXPECTED [{0}]".format(rep.outcome)
444+
exitStatus=ExitStatusNames.UNEXPECTED
445+
exitStatusInfo=rep.outcome
430446
# [2025-03-28] It may create a useless problem in new environment.
431447
# assert False
432448

433449
# --------
434450
ifitem_warning_msg_count>0:
435451
TEST_PROCESS_STATS.incrementWarningTestCount(testID,item_warning_msg_count)
436452

453+
# --------
454+
ifexitStatus==ExitStatusNames.FAILED:
455+
assertitem_error_msg_count>0
456+
pass
457+
else:
458+
TestServices.CleanTestTmpDirBeforeExit(item)
459+
437460
# --------
438461
asserttype(TEST_PROCESS_STATS.cTotalDuration)==datetime.timedelta# noqa: E721
439462
asserttype(testDurration)==datetime.timedelta# noqa: E721
@@ -442,11 +465,17 @@ def helper__makereport__call(
442465

443466
asserttestDurration<=TEST_PROCESS_STATS.cTotalDuration
444467

468+
# --------
469+
exitStatusLineData=exitStatus
470+
471+
ifexitStatusInfoisnotNone:
472+
exitStatusLineData+=" [{}]".format(exitStatusInfo)
473+
445474
# --------
446475
logging.info("*")
447476
logging.info("* DURATION : {0}".format(timedelta_to_human_text(testDurration)))
448477
logging.info("*")
449-
logging.info("* EXIT STATUS : {0}".format(exitStatus))
478+
logging.info("* EXIT STATUS : {0}".format(exitStatusLineData))
450479
logging.info("* ERROR COUNT : {0}".format(item_error_msg_count))
451480
logging.info("* WARNING COUNT: {0}".format(item_warning_msg_count))
452481
logging.info("*")
@@ -694,7 +723,7 @@ def helper__calc_W(n: int) -> int:
694723

695724

696725
# ------------------------------------------------------------------------
697-
defhelper__print_test_list(tests:list[str])->None:
726+
defhelper__print_test_list(tests:typing.List[str])->None:
698727
asserttype(tests)==list# noqa: E721
699728

700729
asserthelper__calc_W(9)==1
@@ -721,7 +750,7 @@ def helper__print_test_list(tests: list[str]) -> None:
721750

722751

723752
# ------------------------------------------------------------------------
724-
defhelper__print_test_list2(tests:list[str,int])->None:
753+
defhelper__print_test_list2(tests:typing.List[T_TUPLE__str_int])->None:
725754
asserttype(tests)==list# noqa: E721
726755

727756
asserthelper__calc_W(9)==1
@@ -773,7 +802,9 @@ def LOCAL__print_line1_with_header(header: str):
773802
assertheader!=""
774803
logging.info(C_LINE1+" ["+header+"]")
775804

776-
defLOCAL__print_test_list(header:str,test_count:int,test_list:list[str]):
805+
defLOCAL__print_test_list(
806+
header:str,test_count:int,test_list:typing.List[str]
807+
):
777808
asserttype(header)==str# noqa: E721
778809
asserttype(test_count)==int# noqa: E721
779810
asserttype(test_list)==list# noqa: E721
@@ -788,7 +819,7 @@ def LOCAL__print_test_list(header: str, test_count: int, test_list: list[str]):
788819
logging.info("")
789820

790821
defLOCAL__print_test_list2(
791-
header:str,test_count:int,test_list:list[str,int]
822+
header:str,test_count:int,test_list:typing.List[T_TUPLE__str_int]
792823
):
793824
asserttype(header)==str# noqa: E721
794825
asserttype(test_count)==int# noqa: E721
@@ -880,13 +911,9 @@ def pytest_configure(config: pytest.Config) -> None:
880911
log_name=TestStartupData.GetCurrentTestWorkerSignature()
881912
log_name+=".log"
882913

883-
ifTestConfigPropNames.TEST_CFG__LOG_DIRinos.environ:
884-
log_path_v=os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
885-
log_path=pathlib.Path(log_path_v)
886-
else:
887-
log_path=config.rootpath.joinpath("logs")
914+
log_dir=TestStartupData.GetRootLogDir()
888915

889-
log_path.mkdir(exist_ok=True)
916+
pathlib.Path(log_dir).mkdir(exist_ok=True)
890917

891918
logging_plugin:_pytest.logging.LoggingPlugin=config.pluginmanager.get_plugin(
892919
"logging-plugin"
@@ -895,7 +922,7 @@ def pytest_configure(config: pytest.Config) -> None:
895922
assertlogging_pluginisnotNone
896923
assertisinstance(logging_plugin,_pytest.logging.LoggingPlugin)
897924

898-
logging_plugin.set_log_path(str(log_path/log_name))
925+
logging_plugin.set_log_path(os.path.join(log_dir,log_name))
899926

900927

901928
# /////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp