diff --git a/tests/test_meta_invoice.py b/tests/test_meta_invoice.py index 88ed46bdc897797282f39f03e4544c46de48abf7..7de49c5016799d6a08c4aa3887d0ba290ebd9d06 100644 --- a/tests/test_meta_invoice.py +++ b/tests/test_meta_invoice.py @@ -37,6 +37,9 @@ NON_REQUIRED_ACCOUNTS = { TEST_KEY = 'invoice' +MISSING_MSG = f'{{}} missing {TEST_KEY}'.format +WRONG_TYPE_MSG = f'{{}} has wrong type of {TEST_KEY}: expected str but is a {{}}'.format + @pytest.fixture(scope='module') def hook(): config = testutil.TestConfig() @@ -77,13 +80,12 @@ def test_bad_type_values_on_postings(hook, acct1, acct2, value): (acct2, -25), (acct1, 25, {TEST_KEY: value}), ]) - expected_msg = "{} has wrong type of {}: expected str but is a {}".format( - acct1, - TEST_KEY, - type(value).__name__, - ) + expected = { + MISSING_MSG(acct1), + WRONG_TYPE_MSG(acct1, type(value).__name__), + } actual = {error.message for error in hook.run(txn)} - assert actual == {expected_msg} + assert actual == expected @pytest.mark.parametrize('acct1,acct2,value', testutil.combine_values( REQUIRED_ACCOUNTS, @@ -120,13 +122,12 @@ def test_bad_type_values_on_transaction(hook, acct1, acct2, value): (acct2, -25), (acct1, 25), ]) - expected_msg = "{} has wrong type of {}: expected str but is a {}".format( - acct1, - TEST_KEY, - type(value).__name__, - ) + expected = { + MISSING_MSG(acct1), + WRONG_TYPE_MSG(acct1, type(value).__name__), + } actual = {error.message for error in hook.run(txn)} - assert actual == {expected_msg} + assert actual == expected @pytest.mark.parametrize('acct1,acct2', testutil.combine_values( REQUIRED_ACCOUNTS,