8000 Testgres tests create log dir in exact place by dmitry-lipetsk · Pull Request #243 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Testgres tests create log dir in exact place #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Testgres tests create log dir in exact place
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.
  • Loading branch information
dmitry-lipetsk committed May 1, 2025
commit 25d5bfb228b32cb39a4c5810e529711104fa74e3
28 changes: 21 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def CalcRootDir() -> str:
r = os.path.abspath(r)
return r

# --------------------------------------------------------------------
def CalcRootLogDir() -> str:
if TestConfigPropNames.TEST_CFG__LOG_DIR in os.environ:
resultPath = os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
else:
rootDir = __class__.CalcRootDir()
resultPath = os.path.join(rootDir, "logs")

assert type(resultPath) == str # noqa: E721
return resultPath

# --------------------------------------------------------------------
def CalcCurrentTestWorkerSignature() -> str:
currentPID = os.getpid()
Expand Down Expand Up @@ -86,11 +97,18 @@ class TestStartupData:
TestStartupData__Helper.CalcCurrentTestWorkerSignature()
)

sm_RootLogDir: str = TestStartupData__Helper.CalcRootLogDir()

# --------------------------------------------------------------------
def GetRootDir() -> str:
assert type(__class__.sm_RootDir) == str # noqa: E721
return __class__.sm_RootDir

# --------------------------------------------------------------------
def GetRootLogDir() -> str:
assert type(__class__.sm_RootLogDir) == str # noqa: E721
return __class__.sm_RootLogDir

# --------------------------------------------------------------------
def GetCurrentTestWorkerSignature() -> str:
assert type(__class__.sm_CurrentTestWorkerSignature) == str # noqa: E721
Expand Down Expand Up @@ -954,13 +972,9 @@ def pytest_configure(config: pytest.Config) -> None:
log_name = TestStartupData.GetCurrentTestWorkerSignature()
log_name += ".log"

if TestConfigPropNames.TEST_CFG__LOG_DIR in os.environ:
log_path_v = os.environ[TestConfigPropNames.TEST_CFG__LOG_DIR]
log_path = pathlib.Path(log_path_v)
else:
log_path = config.rootpath.joinpath("logs")
log_dir = TestStartupData.GetRootLogDir()

log_path.mkdir(exist_ok=True)
pathlib.Path(log_dir).mkdir(exist_ok=True)

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

logging_plugin.set_log_path(str(log_path / log_name))
logging_plugin.set_log_path(os.path.join(log_dir, log_name))


# /////////////////////////////////////////////////////////////////////////////
0