Skip to content

Commit 9bc744c

Browse files
committed
tests: protect logging configuration against the test being ran
Tool can adjust logging level, and will be cranking it to full debug shortly for better test failure output capturing. Signed-off-by: Brian Harring <[email protected]>
1 parent eaae793 commit 9bc744c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/conftest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import copy
2+
import logging
13
import os
24
import shutil
35
import tempfile
@@ -13,7 +15,7 @@
1315

1416
@pytest.fixture(scope="session")
1517
def temporary_home():
16-
"""Generate a temporary directory and set$HOME to it."""
18+
"""Generate a temporary directory and set $HOME to it."""
1719
old_home = os.environ.get("HOME")
1820
new_home = None
1921
try:
@@ -28,6 +30,18 @@ def temporary_home():
2830
shutil.rmtree(new_home) # pyright: ignore[reportArgumentType]
2931

3032

33+
@pytest.fixture(autouse=True, scope="function")
34+
def protect_logging():
35+
"""Protect pytest logging configuration from any tool logging manipulation"""
36+
state = None
37+
try:
38+
state = copy.deepcopy(logging.root)
39+
yield
40+
finally:
41+
if state is not None:
42+
logging.root = state
43+
44+
3145
@pytest.fixture(scope="session")
3246
def tool(temporary_home):
3347
"""Generate a tool utility for running pkgdev."""

0 commit comments

Comments
 (0)