-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3042 from abravalheri/issue-3038
Ensure log level is set correctly (and `setuptools.logging.set_threshold` is called)
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
|
||
setup_py = """\ | ||
from setuptools import setup | ||
setup( | ||
name="test_logging", | ||
version="0.0" | ||
) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"flag, expected_level", [("--dry-run", "INFO"), ("--verbose", "DEBUG")] | ||
) | ||
def test_verbosity_level(tmp_path, monkeypatch, flag, expected_level): | ||
"""Make sure the correct verbosity level is set (issue #3038)""" | ||
import setuptools # noqa: Import setuptools to monkeypatch distutils | ||
import distutils # <- load distutils after all the patches take place | ||
|
||
logger = logging.Logger(__name__) | ||
monkeypatch.setattr(logging, "root", logger) | ||
unset_log_level = logger.getEffectiveLevel() | ||
assert logging.getLevelName(unset_log_level) == "NOTSET" | ||
|
||
setup_script = tmp_path / "setup.py" | ||
setup_script.write_text(setup_py) | ||
dist = distutils.core.run_setup(setup_script, stop_after="init") | ||
dist.script_args = [flag, "sdist"] | ||
dist.parse_command_line() # <- where the log level is set | ||
log_level = logger.getEffectiveLevel() | ||
log_level_name = logging.getLevelName(log_level) | ||
assert log_level_name == expected_level |