2018-08-20 06:29:29 +02:00
|
|
|
import os
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
import py
|
2018-02-08 19:38:45 +01:00
|
|
|
import pytest
|
2017-04-26 23:00:11 +02:00
|
|
|
import hy
|
2019-04-18 20:28:19 +02:00
|
|
|
from hy._compat import PY3, PY36, PY38
|
2017-04-26 23:00:11 +02:00
|
|
|
|
2017-08-31 07:36:06 +02:00
|
|
|
NATIVE_TESTS = os.path.join("", "tests", "native_tests", "")
|
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
_fspath_pyimport = py.path.local.pyimport
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_ignore_collect(path, config):
|
2018-08-25 04:56:00 +02:00
|
|
|
return (("py3_only" in path.basename and not PY3) or
|
2019-04-18 20:28:19 +02:00
|
|
|
("py36_only" in path.basename and not PY36) or
|
|
|
|
("py38_only" in path.basename and not PY38) or None)
|
2018-08-20 06:29:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
def pyimport_patch_mismatch(self, **kwargs):
|
|
|
|
"""Lame fix for https://github.com/pytest-dev/py/issues/195"""
|
|
|
|
try:
|
|
|
|
return _fspath_pyimport(self, **kwargs)
|
|
|
|
except py.path.local.ImportMismatchError:
|
|
|
|
pkgpath = self.pypkgpath()
|
|
|
|
if pkgpath is None:
|
|
|
|
pkgroot = self.dirpath()
|
|
|
|
modname = self.purebasename
|
|
|
|
else:
|
|
|
|
pkgroot = pkgpath.dirpath()
|
|
|
|
names = self.new(ext="").relto(pkgroot).split(self.sep)
|
|
|
|
if names[-1] == "__init__":
|
|
|
|
names.pop()
|
|
|
|
modname = ".".join(names)
|
|
|
|
|
|
|
|
res = importlib.import_module(modname)
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
py.path.local.pyimport = pyimport_patch_mismatch
|
|
|
|
|
|
|
|
|
2017-04-26 23:00:11 +02:00
|
|
|
def pytest_collect_file(parent, path):
|
|
|
|
if (path.ext == ".hy"
|
2018-08-20 06:29:29 +02:00
|
|
|
and NATIVE_TESTS in path.dirname + os.sep
|
|
|
|
and path.basename != "__init__.hy"):
|
|
|
|
|
|
|
|
pytest_mod = pytest.Module(path, parent)
|
|
|
|
return pytest_mod
|