From 62d56d93e2637a0ecc9585203916b39435a35778 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 13 Dec 2024 16:17:52 -0600 Subject: [PATCH] test: improve test err --- src/ape/managers/_contractscache.py | 18 ++++++++---------- tests/functional/test_contracts_cache.py | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ape/managers/_contractscache.py b/src/ape/managers/_contractscache.py index 5a72e28aab..24821a2137 100644 --- a/src/ape/managers/_contractscache.py +++ b/src/ape/managers/_contractscache.py @@ -12,13 +12,7 @@ from ape.api.networks import ProxyInfoAPI from ape.api.query import ContractCreation, ContractCreationQuery from ape.contracts.base import ContractContainer, ContractInstance -from ape.exceptions import ( - ContractNotFoundError, - ConversionError, - CustomError, - QueryEngineError, - ApeException, -) +from ape.exceptions import ApeException, ContractNotFoundError, ConversionError, CustomError from ape.logging import logger from ape.managers._deploymentscache import Deployment, DeploymentDiskCache from ape.managers.base import BaseManager @@ -695,9 +689,13 @@ def instance_at( ) elif not isinstance(contract_type, ContractType): - raise TypeError( - f"Expected type '{ContractType.__name__}' for argument 'contract_type'." - ) + prefix = f"Expected type '{ContractType.__name__}' for argument 'contract_type'" + try: + suffix = f"; Given '{type(contract_type).__name__}'." + except Exception: + suffix = "." + + raise TypeError(f"{prefix}{suffix}") if not txn_hash: # Check for txn_hash in deployments. diff --git a/tests/functional/test_contracts_cache.py b/tests/functional/test_contracts_cache.py index 908aaba1d6..d9350bff7f 100644 --- a/tests/functional/test_contracts_cache.py +++ b/tests/functional/test_contracts_cache.py @@ -38,7 +38,7 @@ def test_instance_at_when_given_contract_type(chain, contract_instance): def test_instance_at_when_given_name_as_contract_type(chain, contract_instance): - expected_match = "Expected type 'ContractType' for argument 'contract_type'." + expected_match = "Expected type 'ContractType' for argument 'contract_type'; Given 'str'." with pytest.raises(TypeError, match=expected_match): address = str(contract_instance.address) bad_contract_type = contract_instance.contract_type.name