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.
This commit is contained in:
parent
7f4f373e89
commit
0a612f24ac
|
@ -1,7 +1,9 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from tabulate import tabulate
|
||||||
|
|
||||||
from utils import login, get_table
|
from utils import login, get_table
|
||||||
|
|
||||||
|
@ -20,6 +22,14 @@ def pytest_generate_tests(metafunc):
|
||||||
metafunc.parametrize(['visualization'], [[x] for x in tables])
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
def freezetime(freezer):
|
def freezetime(freezer):
|
||||||
freezer.move_to('2018-12-07 16:53:00')
|
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)
|
visualization_page = response.click(lambda x: x == visualization)
|
||||||
assert 'big-msg-info' not in visualization_page
|
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)
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -24,6 +24,7 @@ deps =
|
||||||
WebTest
|
WebTest
|
||||||
django-webtest<1.9.3
|
django-webtest<1.9.3
|
||||||
pyquery
|
pyquery
|
||||||
|
tabulate
|
||||||
commands =
|
commands =
|
||||||
dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/}
|
dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/}
|
||||||
[pytest]
|
[pytest]
|
||||||
|
|
Loading…
Reference in New Issue