Skip to content

Commit

Permalink
logging: use logger.warning for DeprecatedArgumentAction (#9630)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzorin committed Mar 27, 2023
1 parent a16f316 commit fbf7f1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion certbot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).

### Fixed

*
* Deprecated flags were inadvertently not printing warnings since v1.16.0. This is now fixed.

More details about these changes can be found on our GitHub repo.

Expand Down
3 changes: 1 addition & 2 deletions certbot/certbot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from typing import Set
from typing import Tuple
from typing import Union
import warnings

import configargparse

Expand Down Expand Up @@ -455,7 +454,7 @@ class DeprecatedArgumentAction(argparse.Action):
"""Action to log a warning when an argument is used."""
def __call__(self, unused1: Any, unused2: Any, unused3: Any,
option_string: Optional[str] = None) -> None:
warnings.warn("Use of %s is deprecated." % option_string, DeprecationWarning)
logger.warning("Use of %s is deprecated.", option_string)


def add_deprecated_argument(add_argument: Callable[..., None], argument_name: str,
Expand Down
8 changes: 4 additions & 4 deletions certbot/tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,19 @@ def _call(self, argument_name, nargs):

def test_warning_no_arg(self):
self._call("--old-option", 0)
with mock.patch("warnings.warn") as mock_warn:
with mock.patch("certbot.util.logger.warning") as mock_warn:
self.parser.parse_args(["--old-option"])
assert mock_warn.call_count == 1
assert "is deprecated" in mock_warn.call_args[0][0]
assert "--old-option" in mock_warn.call_args[0][0]
assert "--old-option" in mock_warn.call_args[0][1]

def test_warning_with_arg(self):
self._call("--old-option", 1)
with mock.patch("warnings.warn") as mock_warn:
with mock.patch("certbot.util.logger.warning") as mock_warn:
self.parser.parse_args(["--old-option", "42"])
assert mock_warn.call_count == 1
assert "is deprecated" in mock_warn.call_args[0][0]
assert "--old-option" in mock_warn.call_args[0][0]
assert "--old-option" in mock_warn.call_args[0][1]

def test_help(self):
self._call("--old-option", 2)
Expand Down

0 comments on commit fbf7f1f

Please sign in to comment.