From 8df2206ccf0f1208e00201d8cb6834a1ca2b1973 Mon Sep 17 00:00:00 2001 From: Martin Vahlensieck Date: Thu, 16 May 2024 09:17:56 +0200 Subject: [PATCH] Convert decimals to integers if possible --- conftest.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 77de629f..b31c677c 100644 --- a/conftest.py +++ b/conftest.py @@ -1,3 +1,4 @@ +import decimal import sys import pytest @@ -25,8 +26,13 @@ def add_cur(request, doctest_namespace): cur.close() def myprint(*objects, sep=' ', end='\n', file=None, flush=False): + def toint(i): + if isinstance(i, decimal.Decimal) and int(i) == i: + return int(i) + else: + return i if len(objects) == 1 and isinstance(objects[0], dict): - print('{' + ', '.join(map(lambda i: f'{repr(i[0])}: {repr(i[1])}', sorted(objects[0].items()))) + '}') + print('{' + ', '.join(map(lambda i: f'{repr(i[0])}: {repr(toint(i[1]))}', sorted(objects[0].items()))) + '}') else: print(*objects, sep=sep, end=end, file=file, flush=flush)