taskwiki/tests/conftest.py
Tomas Janousek f2d1c162e2 tests: Fix "Different tests were collected" in python 3.5
pytest-xdist requires all subprocesses to collect the tests in the same
order. Python 3.5, however, randomizes order of dict keys.
2020-08-02 17:24:20 -04:00

46 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
import pytest
import re
# enable assertion introspection for the common code in tests.base
pytest.register_assert_rewrite('tests.base')
markup_headers = {
'default': {
'HEADER1': "= %s =",
'HEADER2': "== %s ==",
'HEADER3': "=== %s ===",
},
'markdown': {
'HEADER1': "# %s",
'HEADER2': "## %s",
'HEADER3': "### %s",
}
}
@pytest.fixture(params=sorted(markup_headers.keys()))
def test_syntax(request):
markup = request.param
format_header_dict = markup_headers[markup]
def header_expand(string):
"""
The function perform string replacement of 'HEADER1(.+)' with a header
syntax for a markup containing the string found in '.+'. This function
is constructed with a dict of three header levels containing their regex
and actual syntax.
When a markup is selected and this function is executed, the function
will find instance of 'HEADER1' with 1 being any number between 1 and 3
inclusive.
"""
for header_level, format_header in format_header_dict.items():
regex = header_level + '\((.*?)\)'
string = re.sub(regex,
lambda match: format_header % match.group(1),
string)
return string
return (markup, header_expand)