Skip to content

Commit

Permalink
Renovate conftest (and require pytest 6+)
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Nov 1, 2022
1 parent 6c36035 commit 2c7204c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions conftest.py
@@ -1,14 +1,20 @@
from pathlib import Path

from _pytest.doctest import DoctestModule
from py.path import local

collect_ignore = ['tests/messages/data', 'setup.py']
babel_path = local(__file__).dirpath().join('babel')
babel_path = Path(__file__).parent / 'babel'


# Via the stdlib implementation of Path.is_relative_to in Python 3.9
def _is_relative(p1: Path, p2: Path) -> bool:
try:
p1.relative_to(p2)
return True
except ValueError:
return False


def pytest_collect_file(path, parent):
if babel_path.common(path) == babel_path:
if path.ext == ".py":
# TODO: remove check when dropping support for old Pytest
if hasattr(DoctestModule, "from_parent"):
return DoctestModule.from_parent(parent, fspath=path)
return DoctestModule(path, parent)
def pytest_collect_file(file_path: Path, parent):
if _is_relative(file_path, babel_path) and file_path.suffix == '.py':
return DoctestModule.from_parent(parent, path=file_path)
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -5,7 +5,7 @@ envlist =

[testenv]
deps =
pytest
pytest>=6.0
pytest-cov
freezegun==0.3.12
backports.zoneinfo;python_version<"3.9"
Expand Down

0 comments on commit 2c7204c

Please sign in to comment.