From 0a612f24aca40c403fc3a7964e44134cc156270c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 30 Nov 2019 03:52:14 +0100 Subject: [PATCH 02/13] tests: use tabulate to compare tables (#38067) Comparing strings with assert gives better diffs thant comparing list of lists when using the pytest's `-vv` option. --- tests/test_schema2.py | 15 ++++++++++++++- tox.ini | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_schema2.py b/tests/test_schema2.py index a060f6b..adaa1a7 100644 --- a/tests/test_schema2.py +++ b/tests/test_schema2.py @@ -1,7 +1,9 @@ import json import os +import re import pytest +from tabulate import tabulate from utils import login, get_table @@ -20,6 +22,14 @@ def pytest_generate_tests(metafunc): metafunc.parametrize(['visualization'], [[x] for x in tables]) +def assert_equal_tables(table1, table2): + t1 = tabulate(table1) + t2 = tabulate(table2) + t1 = re.sub(' +', ' ', t1) + t2 = re.sub(' +', ' ', t2) + assert t1 == t2 + + @pytest.fixture(autouse=True) def freezetime(freezer): freezer.move_to('2018-12-07 16:53:00') @@ -31,4 +41,7 @@ def test_simple(schema2, app, admin, visualization): visualization_page = response.click(lambda x: x == visualization) assert 'big-msg-info' not in visualization_page - assert schema2['tables'][visualization] == get_table(visualization_page) + table = get_table(visualization_page) + assert_equal_tables( + schema2['tables'][visualization], + table) diff --git a/tox.ini b/tox.ini index b571306..a4e6d5c 100644 --- a/tox.ini +++ b/tox.ini @@ -24,6 +24,7 @@ deps = WebTest django-webtest<1.9.3 pyquery + tabulate commands = dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/} [pytest] -- 2.23.0