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

Commit9b0c0a4

Browse files
[tests] Creation of "dummy/empty" log file for xdist controller is fixed. (#282)
This commit does the following things:1) It detects a kind of process (master/worker)2) It detects a mode of process (collect/exec)3) It creates/configures a log file for worker/exec only4) It uses pytest_sessionfinish hook instead run_after_tests fixture
1 parent4c806a0 commit9b0c0a4

File tree

1 file changed

+118
-6
lines changed

1 file changed

+118
-6
lines changed

‎tests/conftest.py

Lines changed: 118 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
importmath
1010
importdatetime
1111
importtyping
12+
importenum
1213

1314
import_pytest.outcomes
1415
import_pytest.unittest
@@ -39,6 +40,30 @@
3940
g_critical_msg_count_key=pytest.StashKey[int]()
4041

4142

43+
# /////////////////////////////////////////////////////////////////////////////
44+
# T_TEST_PROCESS_KIND
45+
46+
classT_TEST_PROCESS_KIND(enum.Enum):
47+
Master=1
48+
Worker=2
49+
50+
51+
# /////////////////////////////////////////////////////////////////////////////
52+
# T_TEST_PROCESS_MODE
53+
54+
classT_TEST_PROCESS_MODE(enum.Enum):
55+
Collect=1
56+
ExecTests=2
57+
58+
59+
# /////////////////////////////////////////////////////////////////////////////
60+
61+
g_test_process_kind:typing.Optional[T_TEST_PROCESS_KIND]=None
62+
g_test_process_mode:typing.Optional[T_TEST_PROCESS_MODE]=None
63+
64+
g_worker_log_is_created:typing.Optional[bool]=None
65+
66+
4267
# /////////////////////////////////////////////////////////////////////////////
4368
# TestConfigPropNames
4469

@@ -857,13 +882,37 @@ def helper__print_test_list2(tests: typing.List[T_TUPLE__str_int]) -> None:
857882

858883

859884
# /////////////////////////////////////////////////////////////////////////////
885+
# SUMMARY BUILDER
886+
887+
888+
@pytest.hookimpl(trylast=True)
889+
defpytest_sessionfinish():
890+
#
891+
# NOTE: It should execute after logging.pytest_sessionfinish
892+
#
893+
894+
globalg_test_process_kind# noqa: F824
895+
globalg_test_process_mode# noqa: F824
896+
globalg_worker_log_is_created# noqa: F824
860897

898+
assertg_test_process_kindisnotNone
899+
asserttype(g_test_process_kind)==T_TEST_PROCESS_KIND# noqa: E721
861900

862-
@pytest.fixture(autouse=True,scope="session")
863-
defrun_after_tests(request:pytest.FixtureRequest):
864-
assertisinstance(request,pytest.FixtureRequest)
901+
ifg_test_process_kind==T_TEST_PROCESS_KIND.Master:
902+
return
903+
904+
assertg_test_process_kind==T_TEST_PROCESS_KIND.Worker
865905

866-
yield
906+
assertg_test_process_modeisnotNone
907+
asserttype(g_test_process_mode)==T_TEST_PROCESS_MODE# noqa: E721
908+
909+
ifg_test_process_mode==T_TEST_PROCESS_MODE.Collect:
910+
return
911+
912+
assertg_test_process_mode==T_TEST_PROCESS_MODE.ExecTests
913+
914+
asserttype(g_worker_log_is_created)==bool# noqa: E721
915+
assertg_worker_log_is_created
867916

868917
C_LINE1="---------------------------"
869918

@@ -975,8 +1024,33 @@ def LOCAL__print_test_list2(
9751024
# /////////////////////////////////////////////////////////////////////////////
9761025

9771026

1027+
defhelper__detect_test_process_kind(config:pytest.Config)->T_TEST_PROCESS_KIND:
1028+
assertisinstance(config,pytest.Config)
1029+
1030+
#
1031+
# xdist' master process registers DSession plugin.
1032+
#
1033+
p=config.pluginmanager.get_plugin("dsession")
1034+
1035+
ifpisnotNone:
1036+
returnT_TEST_PROCESS_KIND.Master
1037+
1038+
returnT_TEST_PROCESS_KIND.Worker
1039+
1040+
1041+
# ------------------------------------------------------------------------
1042+
defhelper__detect_test_process_mode(config:pytest.Config)->T_TEST_PROCESS_MODE:
1043+
assertisinstance(config,pytest.Config)
1044+
1045+
ifconfig.getvalue("collectonly"):
1046+
returnT_TEST_PROCESS_MODE.Collect
1047+
1048+
returnT_TEST_PROCESS_MODE.ExecTests
1049+
1050+
1051+
# ------------------------------------------------------------------------
9781052
@pytest.hookimpl(trylast=True)
979-
defpytest_configure(config:pytest.Config)->None:
1053+
defhelper__pytest_configure__logging(config:pytest.Config)->None:
9801054
assertisinstance(config,pytest.Config)
9811055

9821056
log_name=TestStartupData.GetCurrentTestWorkerSignature()
@@ -993,7 +1067,45 @@ def pytest_configure(config: pytest.Config) -> None:
9931067
assertlogging_pluginisnotNone
9941068
assertisinstance(logging_plugin,_pytest.logging.LoggingPlugin)
9951069

996-
logging_plugin.set_log_path(os.path.join(log_dir,log_name))
1070+
log_file_path=os.path.join(log_dir,log_name)
1071+
assertlog_file_pathisnotNone
1072+
asserttype(log_file_path)==str# noqa: E721
9971073

1074+
logging_plugin.set_log_path(log_file_path)
1075+
return
1076+
1077+
1078+
# ------------------------------------------------------------------------
1079+
@pytest.hookimpl(trylast=True)
1080+
defpytest_configure(config:pytest.Config)->None:
1081+
assertisinstance(config,pytest.Config)
1082+
1083+
globalg_test_process_kind
1084+
globalg_test_process_mode
1085+
globalg_worker_log_is_created
1086+
1087+
assertg_test_process_kindisNone
1088+
assertg_test_process_modeisNone
1089+
assertg_worker_log_is_createdisNone
1090+
1091+
g_test_process_mode=helper__detect_test_process_mode(config)
1092+
g_test_process_kind=helper__detect_test_process_kind(config)
1093+
1094+
asserttype(g_test_process_kind)==T_TEST_PROCESS_KIND# noqa: E721
1095+
asserttype(g_test_process_mode)==T_TEST_PROCESS_MODE# noqa: E721
1096+
1097+
ifg_test_process_kind==T_TEST_PROCESS_KIND.Master:
1098+
pass
1099+
else:
1100+
assertg_test_process_kind==T_TEST_PROCESS_KIND.Worker
1101+
1102+
ifg_test_process_mode==T_TEST_PROCESS_MODE.Collect:
1103+
g_worker_log_is_created=False
1104+
else:
1105+
assertg_test_process_mode==T_TEST_PROCESS_MODE.ExecTests
1106+
helper__pytest_configure__logging(config)
1107+
g_worker_log_is_created=True
1108+
1109+
return
9981110

9991111
# /////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp