Skip to content

Commit 57456db

Browse files
DeborahOlaboyeSamWilsn
authored andcommitted
Added --log-to command-line argument to pytest logging plugin and configure tox environments to write logs to {toxworkdir}/logs
1 parent 00eb741 commit 57456db

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/tests/src/pytest_plugins/custom_logging/plugin_logging.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ def pytest_addoption(parser: pytest.Parser) -> None: # noqa: D103
268268
"CRITICAL, default - INFO. An integer in [0, 50] may be also provided."
269269
),
270270
)
271+
logging_group.addoption(
272+
"--log-to",
273+
action="store",
274+
default=None,
275+
dest="eest_log_dir",
276+
help="Directory to write log files. Defaults to ./logs if not specified.",
277+
)
271278

272279

273280
@functools.cache
@@ -317,16 +324,10 @@ def pytest_configure(config: pytest.Config) -> None:
317324

318325
worker_id = os.getenv("PYTEST_XDIST_WORKER", "main")
319326
log_filename = f"{log_stem}-{worker_id}.log"
320-
basetemp_opt = getattr(config.option, "basetemp", None)
321-
tox_work_dir = os.environ.get("TOX_WORK_DIR")
322-
323-
if basetemp_opt:
324-
base_logs_dir = Path(str(basetemp_opt)) / "logs"
325-
elif tox_work_dir:
326-
base_logs_dir = Path(tox_work_dir) / "logs"
327-
else:
328-
base_logs_dir = Path("logs")
329327

328+
# Use --log-to if provided, otherwise default to ./logs
329+
log_dir = getattr(config.option, "eest_log_dir", None)
330+
base_logs_dir = Path(log_dir) if log_dir else Path("logs")
330331
base_logs_dir.mkdir(parents=True, exist_ok=True)
331332
log_file_path = base_logs_dir / log_filename
332333

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ commands =
6363
--cov-branch \
6464
--ignore-glob='tests/json_infra/fixtures/*' \
6565
--basetemp="{temp_dir}/pytest" \
66+
--log-to "{toxworkdir}/logs" \
6667
tests/json_infra
6768

6869
[testenv:py3]
@@ -73,6 +74,7 @@ commands =
7374
-m "not slow and not zkevm and not benchmark" \
7475
-n auto --maxprocesses 10 --dist=loadgroup \
7576
--basetemp="{temp_dir}/pytest" \
77+
--log-to "{toxworkdir}/logs" \
7678
--clean \
7779
--until Osaka \
7880
tests
@@ -93,6 +95,7 @@ commands =
9395
-m "not slow and not zkevm and not benchmark" \
9496
-n auto --maxprocesses 7 --dist=loadgroup \
9597
--basetemp="{temp_dir}/pytest" \
98+
--log-to "{toxworkdir}/logs" \
9699
--clean \
97100
--until Osaka \
98101
tests
@@ -112,6 +115,7 @@ commands =
112115
--ignore-glob='tests/test_t8n.py' \
113116
--ignore-glob='eest_tests/*' \
114117
--basetemp="{temp_dir}/pytest" \
118+
--log-to "{toxworkdir}/logs" \
115119
--optimized \
116120
tests/json_infra
117121

0 commit comments

Comments
 (0)