diff --git a/tests/conftest.py b/tests/conftest.py index 5b5cb641ab..f6e4f47ae3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -381,7 +381,7 @@ class ApeCaplog: def __init__(self, caplog_level: LogLevel = LogLevel.WARNING): self.level = caplog_level self.messages_at_start = list(caplog.messages) - self.set_levels(caplog_level=caplog_level) + self.set_levels(caplog_level) @only_raise_attribute_error def __getattr__(self, name: str) -> Any: @@ -418,10 +418,10 @@ def head(self) -> str: """ return caplog.messages[-1] if len(caplog.messages) else "" - def set_levels(self, caplog_level: LogLevel = LogLevel.WARNING): - self.level = caplog_level - logger.set_level(LogLevel.INFO) - caplog.set_level(caplog_level) + def set_levels(self, level: LogLevel = LogLevel.WARNING): + self.level = level + logger.set_level(level) + caplog.set_level(level) def assert_last_log(self, message: str): assert message in self.head, self.fail_message @@ -446,7 +446,7 @@ def assert_last_log_with_retries( # Reset levels in case they got switched. self.set_levels() - logger.set_level(LogLevel.INFO) + logger.set_level(LogLevel.ERROR) caplog.set_level(LogLevel.WARNING) pytest.fail(self.fail_message) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 5ae46f2f21..85c013a710 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -452,6 +452,7 @@ def _assert_log_values( @pytest.fixture(scope="session") def logger(): + _logger.set_level(LogLevel.ERROR) return _logger diff --git a/tests/functional/test_cli.py b/tests/functional/test_cli.py index e7148683b9..7d1087c98b 100644 --- a/tests/functional/test_cli.py +++ b/tests/functional/test_cli.py @@ -561,12 +561,13 @@ def test_contract_file_paths_argument_given_subdir_relative_to_path( @skip_if_plugin_installed("vyper") def test_contract_file_paths_argument_missing_vyper( - project_with_source_files_contract, runner, contracts_paths_cmd + project_with_source_files_contract, runner, contracts_paths_cmd, ape_caplog ): name = "VyperContract" pm = project_with_source_files_contract arguments = (name, "--project", f"{pm.path}") - result = runner.invoke(contracts_paths_cmd, arguments) + with ape_caplog.at_level(LogLevel.INFO): + result = runner.invoke(contracts_paths_cmd, arguments) expected = ( "Missing compilers for the following file types: '.vy'. " @@ -584,7 +585,8 @@ def test_contract_file_paths_argument_missing_solidity( pm = project_with_source_files_contract with pm.isolate_in_tempdir() as tmp_project: arguments = (name, "--project", f"{tmp_project.path}") - result = runner.invoke(contracts_paths_cmd, arguments) + with logger.at_level(LogLevel.WARNING): + result = runner.invoke(contracts_paths_cmd, arguments) expected = ( "Missing compilers for the following file types: '.sol'. " diff --git a/tests/functional/test_contracts_cache.py b/tests/functional/test_contracts_cache.py index e5827ba926..3b1c01a4a7 100644 --- a/tests/functional/test_contracts_cache.py +++ b/tests/functional/test_contracts_cache.py @@ -4,6 +4,7 @@ from ape import Contract from ape.contracts import ContractInstance from ape.exceptions import ContractNotFoundError, ConversionError +from ape.logging import LogLevel from ape_ethereum.proxies import _make_minimal_proxy from tests.conftest import explorer_test, skip_if_plugin_installed @@ -298,11 +299,13 @@ def test_get_multiple(vyper_contract_instance, solidity_contract_instance, chain ) -def test_get_multiple_no_addresses(chain, caplog): - contract_map = chain.contracts.get_multiple([]) +def test_get_multiple_no_addresses(chain, ape_caplog): + with ape_caplog.at_level(LogLevel.WARNING): + contract_map = chain.contracts.get_multiple([]) + assert "WARNING" in ape_caplog.records[-1].levelname + assert "No addresses provided." in ape_caplog.messages[-1] + assert not contract_map - assert "WARNING" in caplog.records[-1].levelname - assert "No addresses provided." in caplog.messages[-1] def test_get_multiple_include_non_contract_address(vyper_contract_instance, chain, owner): diff --git a/tests/functional/test_logging.py b/tests/functional/test_logging.py index bee67db477..dcd3c77b22 100644 --- a/tests/functional/test_logging.py +++ b/tests/functional/test_logging.py @@ -20,7 +20,8 @@ def test_info(simple_runner): @group_for_testing.command() @ape_cli_context() def cmd(cli_ctx): - cli_ctx.logger.info("this is a test") + with cli_ctx.logger.at_level(LogLevel.INFO): + cli_ctx.logger.info("this is a test") result = simple_runner.invoke(group_for_testing, "cmd") assert "INFO" in result.output @@ -45,7 +46,8 @@ def test_warning(simple_runner): @group_for_testing.command() @ape_cli_context() def cmd(cli_ctx): - cli_ctx.logger.warning("this is a test") + with cli_ctx.logger.at_level(LogLevel.WARNING): + cli_ctx.logger.warning("this is a test") result = simple_runner.invoke(group_for_testing, "cmd") assert "WARNING" in result.output @@ -56,7 +58,8 @@ def test_warning_level_higher(simple_runner): @group_for_testing.command() @ape_cli_context() def cmd(cli_ctx): - cli_ctx.logger.warning("this is a test") + with cli_ctx.logger.at_level(LogLevel.WARNING.value + 1): + cli_ctx.logger.warning("this is a test") logger._did_parse_sys_argv = False result = simple_runner.invoke(group_for_testing, ("cmd", "-v", "ERROR")) @@ -71,7 +74,8 @@ def test_success(simple_runner): @group_for_testing.command() @ape_cli_context(default_log_level=LogLevel.INFO.value) def cmd(cli_ctx): - cli_ctx.logger.success("this is a test") + with cli_ctx.logger.at_level(LogLevel.SUCCESS): + cli_ctx.logger.success("this is a test") logger._did_parse_sys_argv = False result = simple_runner.invoke(group_for_testing, "cmd") @@ -83,7 +87,8 @@ def test_success_level_higher(simple_runner): @group_for_testing.command() @ape_cli_context() def cmd(cli_ctx): - cli_ctx.logger.success("this is a test") + with cli_ctx.logger.at_level(LogLevel.SUCCESS.value + 1): + cli_ctx.logger.success("this is a test") logger._did_parse_sys_argv = False result = simple_runner.invoke(group_for_testing, ("cmd", "-v", "WARNING")) @@ -97,7 +102,8 @@ def test_format(simple_runner): def cmd(cli_ctx): cli_ctx.logger.format(fmt="%(message)s") try: - cli_ctx.logger.success("this is a test") + with cli_ctx.logger.at_level(LogLevel.SUCCESS): + cli_ctx.logger.success("this is a test") finally: cli_ctx.logger.format() diff --git a/tests/functional/test_plugins.py b/tests/functional/test_plugins.py index 07cce2f81a..92aad2fc7b 100644 --- a/tests/functional/test_plugins.py +++ b/tests/functional/test_plugins.py @@ -338,9 +338,11 @@ def test_repr_when_exception(self, mocker): def test_handle_upgrade_result_when_upgrading_to_same_version(ape_caplog, logger): plugin = PluginMetadata(name=THIRD_PARTY[0], version=f"0.{ape_version.minor}.0") handler = ModifyPluginResultHandler(plugin) - ape_caplog.set_levels(LogLevel.INFO) - handler.handle_upgrade_result(0, f"0.{ape_version.minor}.0") - assert f"'{THIRD_PARTY[0]}' already has version '0.{ape_version.minor}.0'" in ape_caplog.head + with ape_caplog.at_level(LogLevel.INFO): + handler.handle_upgrade_result(0, f"0.{ape_version.minor}.0") + assert ( + f"'{THIRD_PARTY[0]}' already has version '0.{ape_version.minor}.0'" in ape_caplog.head + ) class TestApeVersion: