File: conftest.py

package info (click to toggle)
python-sybil 9.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,148 kB
  • sloc: python: 4,510; makefile: 90
file content (44 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from doctest import ELLIPSIS
from pathlib import Path
from typing import Tuple, List

import pytest

from sybil import Sybil
from sybil.parsers.rest import (
    CaptureParser,
    DocTestParser,
    PythonCodeBlockParser,
    SkipParser,
)

pytest_collect_file = Sybil(
    parsers=[
        CaptureParser(),
        DocTestParser(optionflags=ELLIPSIS),
        PythonCodeBlockParser(),
        SkipParser(),
    ],
    patterns=['*.rst', '*.py'],
    excludes=['tests/samples/*', 'tests/*']
).pytest()


def _find_python_files() -> List[Tuple[Path, str]]:
    paths = []
    for path in Path(__file__).parent.rglob('*.py'):
        source = Path(path).read_text()
        paths.append((path, source))
    return paths


@pytest.fixture
def all_python_files():
    return _find_python_files()


def pytest_generate_tests(metafunc):
    files = _find_python_files()
    ids = [str(f[0]) for f in files]
    if "python_file" in metafunc.fixturenames:
        metafunc.parametrize("python_file", files, ids=ids)