Skip to content

Commit

Permalink
Merge branch 'main' into fix-tox-passenv
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev authored Dec 11, 2022
2 parents 7484c7c + 2531b9f commit 8c53e78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions piptools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class LogContext:
stream = sys.stderr

def __init__(self, verbosity: int = 0, indent_width: int = 2):
self.verbosity = verbosity
self.current_indent = 0
self._indent_width = indent_width
self.verbosity = self._initial_verbosity = verbosity
self.current_indent = self._initial_indent = 0
self._indent_width = self._initial_indent_width = indent_width

def log(self, message: str, *args: Any, **kwargs: Any) -> None:
kwargs.setdefault("err", True)
Expand Down Expand Up @@ -58,5 +58,11 @@ def indentation(self) -> Iterator[None]:
finally:
self._dedent()

def reset(self) -> None:
"""Reset logger to initial state."""
self.verbosity = self._initial_verbosity
self.current_indent = self._initial_indent
self._indent_width = self._initial_indent_width


log = LogContext()
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from piptools._compat.pip_compat import uses_pkg_resources
from piptools.cache import DependencyCache
from piptools.exceptions import NoCandidateFound
from piptools.logging import log
from piptools.repositories import PyPIRepository
from piptools.repositories.base import BaseRepository
from piptools.resolver import BacktrackingResolver, LegacyResolver
Expand Down Expand Up @@ -432,3 +433,13 @@ def venv(tmp_path):
check=True,
)
return tmp_path / ("Scripts" if platform.system() == "Windows" else "bin")


@pytest.fixture(autouse=True)
def _reset_log():
"""
Since piptools.logging.log is a global variable we have to restore its initial
state. Some tests can change logger verbosity which might cause a conflict
with other tests that depend on it.
"""
log.reset()

0 comments on commit 8c53e78

Please sign in to comment.