diff --git a/chia/_tests/blockchain/test_augmented_chain.py b/chia/_tests/blockchain/test_augmented_chain.py index c9d751950ef7..326879236c40 100644 --- a/chia/_tests/blockchain/test_augmented_chain.py +++ b/chia/_tests/blockchain/test_augmented_chain.py @@ -93,7 +93,7 @@ async def test_augmented_chain(default_10000_blocks: list[FullBlock]) -> None: with pytest.raises(KeyError): await abc.prev_block_hash([blocks[2].header_hash]) - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await abc.lookup_block_generators(blocks[3].header_hash, {uint32(3)}) block_records = [] @@ -105,11 +105,11 @@ async def test_augmented_chain(default_10000_blocks: list[FullBlock]) -> None: assert abc.height_to_block_record(uint32(1)) == block_records[1] - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await abc.lookup_block_generators(blocks[10].header_hash, {uint32(3), uint32(10)}) # block 1 exists in the chain, but it doesn't have a generator - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await abc.lookup_block_generators(blocks[1].header_hash, {uint32(1)}) expect_gen = blocks[2].transactions_generator diff --git a/chia/_tests/blockchain/test_blockchain.py b/chia/_tests/blockchain/test_blockchain.py index 0b8d639a6d87..f17b87f5d90d 100644 --- a/chia/_tests/blockchain/test_blockchain.py +++ b/chia/_tests/blockchain/test_blockchain.py @@ -4158,24 +4158,24 @@ async def test_lookup_block_generators( # make sure we don't cross the forks if clear_cache: b.clean_block_records() - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await b.lookup_block_generators(peak_1.prev_header_hash, {uint32(516)}) if clear_cache: b.clean_block_records() - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await b.lookup_block_generators(peak_2.prev_header_hash, {uint32(503)}) # make sure we fail when looking up a non-transaction block from the main # chain, regardless of which chain we start at if clear_cache: b.clean_block_records() - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await b.lookup_block_generators(peak_1.prev_header_hash, {uint32(8)}) if clear_cache: b.clean_block_records() - with pytest.raises(ValueError, match="Err.GENERATOR_REF_HAS_NO_GENERATOR"): + with pytest.raises(ValueError, match="Err\\.GENERATOR_REF_HAS_NO_GENERATOR"): await b.lookup_block_generators(peak_2.prev_header_hash, {uint32(8)}) # if we try to look up generators starting from a disconnected block, we diff --git a/chia/_tests/core/data_layer/test_data_rpc.py b/chia/_tests/core/data_layer/test_data_rpc.py index 4ee942e50229..0e06204480c4 100644 --- a/chia/_tests/core/data_layer/test_data_rpc.py +++ b/chia/_tests/core/data_layer/test_data_rpc.py @@ -2277,7 +2277,7 @@ async def test_unsubscribe_unknown( bare_data_layer_api: DataLayerRpcApi, seeded_random: random.Random, ) -> None: - with pytest.raises(RuntimeError, match="No subscription found for the given store_id."): + with pytest.raises(RuntimeError, match="No subscription found for the given store_id"): await bare_data_layer_api.unsubscribe(request={"id": bytes32.random(seeded_random).hex(), "retain": False}) diff --git a/chia/_tests/core/data_layer/test_data_store.py b/chia/_tests/core/data_layer/test_data_store.py index 91a0a2d9430e..a61862ee576e 100644 --- a/chia/_tests/core/data_layer/test_data_store.py +++ b/chia/_tests/core/data_layer/test_data_store.py @@ -594,7 +594,7 @@ async def test_ancestor_table_unique_inserts(data_store: DataStore, store_id: by hash_2 = bytes32.from_hexstr("924be8ff27e84cba17f5bc918097f8410fab9824713a4668a21c8e060a8cab40") await data_store._insert_ancestor_table(hash_1, hash_2, store_id, 2) await data_store._insert_ancestor_table(hash_1, hash_2, store_id, 2) - with pytest.raises(Exception, match="^Requested insertion of ancestor"): + with pytest.raises(Exception, match=r"^Requested insertion of ancestor"): await data_store._insert_ancestor_table(hash_1, hash_1, store_id, 2) await data_store._insert_ancestor_table(hash_1, hash_2, store_id, 2) diff --git a/chia/_tests/core/mempool/test_singleton_fast_forward.py b/chia/_tests/core/mempool/test_singleton_fast_forward.py index ccbb367cbc39..1debc4ff6f12 100644 --- a/chia/_tests/core/mempool/test_singleton_fast_forward.py +++ b/chia/_tests/core/mempool/test_singleton_fast_forward.py @@ -79,7 +79,7 @@ def test_process_fast_forward_spends_unknown_ff() -> None: singleton_ff = SingletonFastForward() # We have no fast forward records yet, so we'll process this coin for the # first time here, but the item's latest singleton lineage returns None - with pytest.raises(ValueError, match="Cannot proceed with singleton spend fast forward."): + with pytest.raises(ValueError, match="Cannot proceed with singleton spend fast forward"): singleton_ff.process_fast_forward_spends( mempool_item=internal_mempool_item, height=TEST_HEIGHT, constants=DEFAULT_CONSTANTS ) diff --git a/chia/_tests/core/test_full_node_rpc.py b/chia/_tests/core/test_full_node_rpc.py index 4a26baced6f5..8bde0aea2b04 100644 --- a/chia/_tests/core/test_full_node_rpc.py +++ b/chia/_tests/core/test_full_node_rpc.py @@ -457,9 +457,9 @@ async def test_signage_points( full_node_service_1.config, ) as client: # Only provide one - with pytest.raises(ValueError, match="sp_hash or challenge_hash must be provided."): + with pytest.raises(ValueError, match="sp_hash or challenge_hash must be provided"): await client.get_recent_signage_point_or_eos(None, None) - with pytest.raises(ValueError, match="Either sp_hash or challenge_hash must be provided, not both."): + with pytest.raises(ValueError, match="Either sp_hash or challenge_hash must be provided, not both"): await client.get_recent_signage_point_or_eos(std_hash(b"0"), std_hash(b"1")) # Not found with pytest.raises(ValueError, match="in cache"): diff --git a/chia/_tests/pools/test_pool_cmdline.py b/chia/_tests/pools/test_pool_cmdline.py index 2dd84d1cbb5e..5684c2a11ce5 100644 --- a/chia/_tests/pools/test_pool_cmdline.py +++ b/chia/_tests/pools/test_pool_cmdline.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import re from dataclasses import dataclass from io import StringIO from typing import Optional, cast @@ -484,7 +485,7 @@ async def test_plotnft_cli_join( wallet_id = await create_new_plotnft(wallet_environments) # Test joining the same pool again - with pytest.raises(click.ClickException, match="already farming to pool http://pool.example.com"): + with pytest.raises(click.ClickException, match=re.escape("already farming to pool http://pool.example.com")): await JoinPlotNFTCMD( rpc_info=NeedsWalletRPC( client_info=client_info, diff --git a/chia/_tests/pools/test_pool_puzzles_lifecycle.py b/chia/_tests/pools/test_pool_puzzles_lifecycle.py index 2838bc790741..c86e06596215 100644 --- a/chia/_tests/pools/test_pool_puzzles_lifecycle.py +++ b/chia/_tests/pools/test_pool_puzzles_lifecycle.py @@ -242,7 +242,7 @@ def test_pool_lifecycle(self): ) # Spend it and hope it fails! with pytest.raises( - BadSpendBundleError, match="condition validation failure Err.ASSERT_ANNOUNCE_CONSUMED_FAILED" + BadSpendBundleError, match="condition validation failure Err\\.ASSERT_ANNOUNCE_CONSUMED_FAILED" ): coin_db.update_coin_store_for_spend_bundle( SpendBundle([singleton_coinsol], G2Element()), time, DEFAULT_CONSTANTS.MAX_BLOCK_COST_CLVM @@ -269,7 +269,7 @@ def test_pool_lifecycle(self): ) # Spend it and hope it fails! with pytest.raises( - BadSpendBundleError, match="condition validation failure Err.ASSERT_ANNOUNCE_CONSUMED_FAILED" + BadSpendBundleError, match="condition validation failure Err\\.ASSERT_ANNOUNCE_CONSUMED_FAILED" ): coin_db.update_coin_store_for_spend_bundle( SpendBundle([singleton_coinsol, bad_coinsol], G2Element()), time, DEFAULT_CONSTANTS.MAX_BLOCK_COST_CLVM @@ -320,7 +320,9 @@ def test_pool_lifecycle(self): (data + singleton.name() + DEFAULT_CONSTANTS.AGG_SIG_ME_ADDITIONAL_DATA), ) # Spend it and hope it fails! - with pytest.raises(BadSpendBundleError, match="condition validation failure Err.ASSERT_HEIGHT_RELATIVE_FAILED"): + with pytest.raises( + BadSpendBundleError, match="condition validation failure Err\\.ASSERT_HEIGHT_RELATIVE_FAILED" + ): coin_db.update_coin_store_for_spend_bundle( SpendBundle([return_coinsol], sig), time, DEFAULT_CONSTANTS.MAX_BLOCK_COST_CLVM ) diff --git a/chia/_tests/pools/test_pool_rpc.py b/chia/_tests/pools/test_pool_rpc.py index 2c26382dd345..04334ae5fb6c 100644 --- a/chia/_tests/pools/test_pool_rpc.py +++ b/chia/_tests/pools/test_pool_rpc.py @@ -1259,7 +1259,7 @@ async def test_join_pool_unsynced( mock.return_value = False # Test joining the same pool via the RPC client - with pytest.raises(ResponseFailureError, match="Wallet needs to be fully synced."): + with pytest.raises(ResponseFailureError, match="Wallet needs to be fully synced"): await wallet_rpc.pw_join_pool( PWJoinPool( wallet_id=uint32(wallet_id), diff --git a/chia/_tests/util/test_misc.py b/chia/_tests/util/test_misc.py index 7978eb19881d..62556508de56 100644 --- a/chia/_tests/util/test_misc.py +++ b/chia/_tests/util/test_misc.py @@ -182,7 +182,7 @@ def test_split_manager_raises_on_second_entry() -> None: split = SplitManager(manager=sync_manager(y=x), object=None) split.enter() - with pytest.raises(Exception, match="^already entered$"): + with pytest.raises(Exception, match=r"^already entered$"): split.enter() @@ -193,7 +193,7 @@ def test_split_manager_raises_on_second_entry_after_exiting() -> None: split.enter() split.exit() - with pytest.raises(Exception, match="^already entered, already exited$"): + with pytest.raises(Exception, match=r"^already entered, already exited$"): split.enter() @@ -204,7 +204,7 @@ def test_split_manager_raises_on_second_exit() -> None: split.enter() split.exit() - with pytest.raises(Exception, match="^already exited$"): + with pytest.raises(Exception, match=r"^already exited$"): split.exit() @@ -213,7 +213,7 @@ def test_split_manager_raises_on_exit_without_entry() -> None: split = SplitManager(manager=sync_manager(y=x), object=None) - with pytest.raises(Exception, match="^not yet entered$"): + with pytest.raises(Exception, match=r"^not yet entered$"): split.exit() @@ -274,7 +274,7 @@ async def test_split_async_manager_raises_on_second_entry() -> None: split = SplitAsyncManager(manager=async_manager(y=x), object=None) await split.enter() - with pytest.raises(Exception, match="^already entered$"): + with pytest.raises(Exception, match=r"^already entered$"): await split.enter() @@ -286,7 +286,7 @@ async def test_split_async_manager_raises_on_second_entry_after_exiting() -> Non await split.enter() await split.exit() - with pytest.raises(Exception, match="^already entered, already exited$"): + with pytest.raises(Exception, match=r"^already entered, already exited$"): await split.enter() @@ -298,7 +298,7 @@ async def test_split_async_manager_raises_on_second_exit() -> None: await split.enter() await split.exit() - with pytest.raises(Exception, match="^already exited$"): + with pytest.raises(Exception, match=r"^already exited$"): await split.exit() @@ -308,7 +308,7 @@ async def test_split_async_manager_raises_on_exit_without_entry() -> None: split = SplitAsyncManager(manager=async_manager(y=x), object=None) - with pytest.raises(Exception, match="^not yet entered$"): + with pytest.raises(Exception, match=r"^not yet entered$"): await split.exit() @@ -390,7 +390,7 @@ async def test_valued_event_set_again_raises_and_does_not_change_value() -> None value = 37 valued_event.set(value) - with pytest.raises(Exception, match="^Value already set$"): + with pytest.raises(Exception, match=r"^Value already set$"): valued_event.set(value + 1) with anyio.fail_after(adjusted_timeout(10)): @@ -404,7 +404,7 @@ async def test_valued_event_wait_raises_if_not_set() -> None: valued_event = ValuedEvent[int]() valued_event._event.set() - with pytest.raises(Exception, match="^Value not set despite event being set$"): + with pytest.raises(Exception, match=r"^Value not set despite event being set$"): with anyio.fail_after(adjusted_timeout(10)): await valued_event.wait() diff --git a/chia/_tests/wallet/cat_wallet/test_cat_wallet.py b/chia/_tests/wallet/cat_wallet/test_cat_wallet.py index 93d04a608149..e60047df6d57 100644 --- a/chia/_tests/wallet/cat_wallet/test_cat_wallet.py +++ b/chia/_tests/wallet/cat_wallet/test_cat_wallet.py @@ -1153,7 +1153,7 @@ async def check_all_there() -> bool: assert action_scope.side_effects.transactions[0].amount == uint64(max_sent_amount) # 3) Generate transaction that is greater than limit - with pytest.raises(ValueError, match="Can't select amount higher than our spendable balance."): + with pytest.raises(ValueError, match="Can't select amount higher than our spendable balance"): async with cat_wallet.wallet_state_manager.new_action_scope( wallet_environments.tx_config, push=False ) as action_scope: diff --git a/chia/_tests/wallet/did_wallet/test_did.py b/chia/_tests/wallet/did_wallet/test_did.py index 0fe6677d7990..ccb12e81f786 100644 --- a/chia/_tests/wallet/did_wallet/test_did.py +++ b/chia/_tests/wallet/did_wallet/test_did.py @@ -791,7 +791,7 @@ async def test_get_info(wallet_environments: WalletTestFramework): coin = (await wallet_0.select_coins(uint64(1), action_scope)).pop() assert coin.amount % 2 == 1 coin_id = coin.name() - with pytest.raises(ValueError, match="The coin is not a DID."): + with pytest.raises(ValueError, match="The coin is not a DID"): await api_0.get_did_info(DIDGetInfo(coin_id.hex())) # Test multiple odd coins @@ -845,7 +845,7 @@ async def test_get_info(wallet_environments: WalletTestFramework): ] ) - with pytest.raises(ValueError, match="This is not a singleton, multiple children coins found."): + with pytest.raises(ValueError, match=r"This is not a singleton, multiple children coins found."): await api_0.get_did_info(DIDGetInfo(coin_1.name().hex())) diff --git a/chia/_tests/wallet/nft_wallet/test_nft_wallet.py b/chia/_tests/wallet/nft_wallet/test_nft_wallet.py index 87d793bd5273..edd809a0ba55 100644 --- a/chia/_tests/wallet/nft_wallet/test_nft_wallet.py +++ b/chia/_tests/wallet/nft_wallet/test_nft_wallet.py @@ -528,7 +528,7 @@ async def test_nft_wallet_creation_and_transfer(wallet_environments: WalletTestF await time_out_assert(30, get_nft_count, 1, nft_wallet_1) # Test an error case - with pytest.raises(ResponseFailureError, match="The NFT doesn't support setting a DID."): + with pytest.raises(ResponseFailureError, match="The NFT doesn't support setting a DID"): await env_1.rpc_client.set_nft_did( NFTSetNFTDID( wallet_id=uint32(env_1.wallet_aliases["nft"]), @@ -659,7 +659,7 @@ async def test_nft_wallet_rpc_creation_and_list(wallet_environments: WalletTestF # test counts assert (await env.rpc_client.count_nfts(NFTCountNFTs(uint32(env.wallet_aliases["nft"])))).count == 2 assert (await env.rpc_client.count_nfts(NFTCountNFTs())).count == 2 - with pytest.raises(ResponseFailureError, match="Wallet 50 not found."): + with pytest.raises(ResponseFailureError, match=r"Wallet 50 not found."): await env.rpc_client.count_nfts(NFTCountNFTs(uint32(50))) diff --git a/ruff.toml b/ruff.toml index fb2dfaa479dd..6bb3e82f6c2a 100644 --- a/ruff.toml +++ b/ruff.toml @@ -90,7 +90,6 @@ ignore = [ "RUF056", # falsy-dict-get-fallback # Should probably fix this "RUF029", # unused-async - "RUF043", # pytest-raises-ambiguous-pattern "RUF046", # unnecessary-cast-to-int "RUF052", # used-dummy-variable