These lines are pretty hard to read, and don’t give very useful output if they fail. Consider refactoring as follows:
0diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
1index 20261f7b7..9b00fc767 100755
2--- a/test/functional/rpc_psbt.py
3+++ b/test/functional/rpc_psbt.py
4@@ -307,25 +307,32 @@ class PSBTTest(BitcoinTestFramework):
5 vout3 = find_output(self.nodes[0], txid3, 11)
6 self.sync_all()
7
8- # Update a PSBT with UTXOs from the node
9- # Bech32 inputs should be filled with witness UTXO. Other inputs should not be filled because they are non-witness
10+ def test_psbt_input_keys(psbt_input, keys):
11+ """Check that the psbt input has only the expected keys."""
12+ assert_equal(set(keys), set(psbt_input.keys()))
13+
14+ # Create a PSBT. None of the inputs are filled initially
15 psbt = self.nodes[1].createpsbt([{"txid":txid1, "vout":vout1},{"txid":txid2, "vout":vout2},{"txid":txid3, "vout":vout3}], {self.nodes[0].getnewaddress():32.999})
16 decoded = self.nodes[1].decodepsbt(psbt)
17- assert "witness_utxo" not in decoded['inputs'][0] and "non_witness_utxo" not in decoded['inputs'][0] and "bip32_derivs" not in decoded['inputs'][0]
18- assert "witness_utxo" not in decoded['inputs'][1] and "non_witness_utxo" not in decoded['inputs'][1] and "bip32_derivs" not in decoded['inputs'][1]
19- assert "witness_utxo" not in decoded['inputs'][2] and "non_witness_utxo" not in decoded['inputs'][2] and "redeem_script" not in decoded['inputs'][2]
20+ test_psbt_input_keys(decoded['inputs'][0], [])
21+ test_psbt_input_keys(decoded['inputs'][1], [])
22+ test_psbt_input_keys(decoded['inputs'][2], [])
23+
24+ # Update a PSBT with UTXOs from the node
25+ # Bech32 inputs should be filled with witness UTXO. Other inputs should not be filled because they are non-witness
26 updated = self.nodes[1].utxoupdatepsbt(psbt)
27 decoded = self.nodes[1].decodepsbt(updated)
28- assert "witness_utxo" in decoded['inputs'][0] and "non_witness_utxo" not in decoded['inputs'][0] and "bip32_derivs" not in decoded['inputs'][0]
29- assert "witness_utxo" not in decoded['inputs'][1] and "non_witness_utxo" not in decoded['inputs'][1] and "bip32_derivs" not in decoded['inputs'][1]
30- assert "witness_utxo" not in decoded['inputs'][2] and "non_witness_utxo" not in decoded['inputs'][2] and "redeem_script" not in decoded['inputs'][2]
31+ test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo'])
32+ test_psbt_input_keys(decoded['inputs'][1], [])
33+ test_psbt_input_keys(decoded['inputs'][2], [])
34+
35 # Try again, now while providing descriptors, making P2SH-segwit work, and causing bip32_derivs and redeem_script to be filled in
36 descs = [self.nodes[1].getaddressinfo(addr)['desc'] for addr in [addr1,addr2,addr3]]
37 updated = self.nodes[1].utxoupdatepsbt(psbt, descs)
38 decoded = self.nodes[1].decodepsbt(updated)
39- assert "witness_utxo" in decoded['inputs'][0] and "non_witness_utxo" not in decoded['inputs'][0] and "bip32_derivs" in decoded['inputs'][0]
40- assert "witness_utxo" not in decoded['inputs'][1] and "non_witness_utxo" not in decoded['inputs'][1] and "bip32_derivs" not in decoded['inputs'][1]
41- assert "witness_utxo" in decoded['inputs'][2] and "non_witness_utxo" not in decoded['inputs'][2] and "redeem_script" in decoded['inputs'][2]
42+ test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'bip32_derivs'])
43+ test_psbt_input_keys(decoded['inputs'][1], [])
44+ test_psbt_input_keys(decoded['inputs'][2], ['witness_utxo', 'bip32_derivs', 'redeem_script'])
45
46 # Two PSBTs with a common input should not be joinable
47 psbt1 = self.nodes[1].createpsbt([{"txid":txid1, "vout":vout1}], {self.nodes[0].getnewaddress():Decimal('10.999')})