Skip to content

Commit 2f550d8

Browse files
Testgres tests create log dir in exact place (#243)
When we do not define TEST_CFG__LOG_DIR it is expected the testgres tests will create a log directory in a root of testgres project folder. We used config.rootpath for detect this folder in pytest_configure function. It was occurred that config.rootpath can point to another (unexpected) place. So we will use exact code to calculate testgres project folder (see TestStartupData.GetRootLogDir) to avid this problem.
1 parent 94d7572 commit 2f550d8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

tests/conftest.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ def CalcRootDir() -> str:
5050
r = os.path.abspath(r)
5151
return r
5252

53+
# --------------------------------------------------------------------
54+
def CalcRootLogDir() -> str:
55+
if TestConfigPropNames.TEST_CFG__LOG_DIR in os.environ:
56+
resultPath = os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
57+
else:
58+
rootDir = __class__.CalcRootDir()
59+
resultPath = os.path.join(rootDir, "logs")
60+
61+
assert type(resultPath) == str # noqa: E721
62+
return resultPath
63+
5364
# --------------------------------------------------------------------
5465
def CalcCurrentTestWorkerSignature() -> str:
5566
currentPID = os.getpid()
@@ -86,11 +97,18 @@ class TestStartupData:
8697
TestStartupData__Helper.CalcCurrentTestWorkerSignature()
8798
)
8899

100+
sm_RootLogDir: str = TestStartupData__Helper.CalcRootLogDir()
101+
89102
# --------------------------------------------------------------------
90103
def GetRootDir() -> str:
91104
assert type(__class__.sm_RootDir) == str # noqa: E721
92105
return __class__.sm_RootDir
93106

107+
# --------------------------------------------------------------------
108+
def GetRootLogDir() -> str:
109+
assert type(__class__.sm_RootLogDir) == str # noqa: E721
110+
return __class__.sm_RootLogDir
111+
94112
# --------------------------------------------------------------------
95113
def GetCurrentTestWorkerSignature() -> str:
96114
assert type(__class__.sm_CurrentTestWorkerSignature) == str # noqa: E721
@@ -954,13 +972,9 @@ def pytest_configure(config: pytest.Config) -> None:
954972
log_name = TestStartupData.GetCurrentTestWorkerSignature()
955973
log_name += ".log"
956974

957-
if TestConfigPropNames.TEST_CFG__LOG_DIR in os.environ:
958-
log_path_v = os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
959-
log_path = pathlib.Path(log_path_v)
960-
else:
961-
log_path = config.rootpath.joinpath("logs")
975+
log_dir = TestStartupData.GetRootLogDir()
962976

963-
log_path.mkdir(exist_ok=True)
977+
pathlib.Path(log_dir).mkdir(exist_ok=True)
964978

965979
logging_plugin: _pytest.logging.LoggingPlugin = config.pluginmanager.get_plugin(
966980
"logging-plugin"
@@ -969,7 +983,7 @@ def pytest_configure(config: pytest.Config) -> None:
969983
assert logging_plugin is not None
970984
assert isinstance(logging_plugin, _pytest.logging.LoggingPlugin)
971985

972-
logging_plugin.set_log_path(str(log_path / log_name))
986+
logging_plugin.set_log_path(os.path.join(log_dir, log_name))
973987

974988

975989
# /////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy