Fetching contributors…
Cannot retrieve contributors at this time
51 lines (36 sloc) 1.34 KB
import os
import importlib
import py
import pytest
import hy
from hy._compat import PY3, PY35, PY36
NATIVE_TESTS = os.path.join("", "tests", "native_tests", "")
_fspath_pyimport = py.path.local.pyimport
def pytest_ignore_collect(path, config):
return (("py3_only" in path.basename and not PY3) or
("py35_only" in path.basename and not PY35) or
("py36_only" in path.basename and not PY36) or None)
def pyimport_patch_mismatch(self, **kwargs):
"""Lame fix for"""
return _fspath_pyimport(self, **kwargs)
except py.path.local.ImportMismatchError:
pkgpath = self.pypkgpath()
if pkgpath is None:
pkgroot = self.dirpath()
modname = self.purebasename
pkgroot = pkgpath.dirpath()
names ="").relto(pkgroot).split(self.sep)
if names[-1] == "__init__":
modname = ".".join(names)
res = importlib.import_module(modname)
return res
py.path.local.pyimport = pyimport_patch_mismatch
def pytest_collect_file(parent, path):
if (path.ext == ".hy"
and NATIVE_TESTS in path.dirname + os.sep
and path.basename != "__init__.hy"):
pytest_mod = pytest.Module(path, parent)
return pytest_mod