| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
from _pytest.doctest import DoctestModule |
| 4 |
|
| 5 |
collect_ignore = [ |
| 6 |
'babel/messages/setuptools_frontend.py', |
| 7 |
'setup.py', |
| 8 |
'tests/messages/data', |
| 9 |
] |
| 10 |
babel_path = Path(__file__).parent / 'babel' |
| 11 |
|
| 12 |
|
| 13 |
# Via the stdlib implementation of Path.is_relative_to in Python 3.9 |
| 14 |
def _is_relative(p1: Path, p2: Path) -> bool: |
| 15 |
try: |
| 16 |
p1.relative_to(p2) |
| 17 |
return True |
| 18 |
except ValueError: |
| 19 |
return False |
| 20 |
|
| 21 |
|
| 22 |
def pytest_collect_file(file_path: Path, parent): |
| 23 |
if _is_relative(file_path, babel_path) and file_path.suffix == '.py': |
| 24 |
return DoctestModule.from_parent(parent, path=file_path) |