Skip to content

Commit a82e556

Browse files
setting pytest logging level at queue time (#33760)
* try setting pytest logging level at queue time * add small note in docs
1 parent c93d858 commit a82e556

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/eng_sys_checks.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [The pyproject.toml](#the-pyprojecttoml)
88
- [Environment variables important to CI](#environment-variables-important-to-ci)
99
- [Atomic Overrides](#atomic-overrides)
10+
- [Enable test logging in CI pipelines](#enable-test-logging-in-ci-pipelines)
1011
- [Analyze Checks](#analyze-checks)
1112
- [MyPy](#mypy)
1213
- [Pyright](#pyright)
@@ -167,6 +168,16 @@ The name that you should use is visible based on what the `tox environment` that
167168
- `AZURE_SERVICEBUS_PYRIGHT=true` <-- enable a check that normally is disabled in `pyproject.toml`
168169
- `AZURE_CORE_PYLINT=false` <-- disable a check that normally runs
169170

171+
### Enable test logging in CI pipelines
172+
173+
You can enable test logging in a pipeline by setting the queue time variable `PYTEST_LOG_LEVEL` to the desired logging [level](https://docs.python.org/3/library/logging.html#logging-levels). For example,
174+
175+
`PYTEST_LOG_LEVEL=INFO`
176+
177+
This also works locally with tox by setting the `PYTEST_LOG_LEVEL` environment variable.
178+
179+
Note that if you want DEBUG level logging with sensitive information unredacted in the test logs, then you still must pass `logging_enable=True` into the client(s) being used in tests.
180+
170181
## Analyze Checks
171182

172183
Analyze job in both nightly CI and pull request validation pipeline runs a set of static analysis using external and internal tools. Following are the list of these static analysis.

eng/tox/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pkgs =
4848

4949
[pytest]
5050
ignore_args=--ignore=.tox --ignore=build --ignore=.eggs
51-
default_args = -rsfE --junitxml={tox_root}/test-junit-{envname}.xml --verbose --cov-branch --durations=10 --ignore=azure {[pytest]ignore_args}
51+
default_args = -rsfE --junitxml={tox_root}/test-junit-{envname}.xml --verbose --cov-branch --durations=10 --ignore=azure {[pytest]ignore_args} --log-cli-level={pytest_log_level}
5252

5353
[testenv]
5454
parallel_show_output =True

eng/tox/toxfile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from logging import getLogger
23
from pathlib import Path
34

@@ -17,3 +18,8 @@ def tox_add_core_config(core_conf: CoreConfigSet, state: State):
1718
next(p for p in Path(core_conf["config_file_path"]).resolve().parents if (p / ".git").exists()),
1819
)
1920

21+
core_conf.add_constant(
22+
"pytest_log_level",
23+
"The log level to use for pytest, supplied as environment or queue time variable PYTEST_LOG_LEVEL",
24+
os.getenv("PYTEST_LOG_LEVEL", "51") # Defaults to no logging
25+
)

0 commit comments

Comments
 (0)