diff --git a/Mk/Uses/python.mk b/Mk/Uses/python.mk --- a/Mk/Uses/python.mk +++ b/Mk/Uses/python.mk @@ -119,6 +119,14 @@ # # noegginfo - Skip an egg-info entry from plist, if defined. # +# pytest - Run tests with latest pytest (devel/py-pytest) +# +# pytest4 - Run tests with pytest 4.x (devel/py-pytest4) +# +# unittest - Run tests with unittest +# +# unittest2 - Run tests with unittest2 (devel/py-unittest2) +# # PYTHON_CMD - Python's command line file name, including the # version number (used for dependencies). # default: ${PYTHONBASE}/bin/${PYTHON_VERSION} @@ -163,6 +171,14 @@ # - Canonical name for egg-info. # default: ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info # +# PYTEST_BROKEN_TESTS - Lists of 'pytest -k' patterns to skip tests which +# require fixing. +# default: +# +# PYTEST_IGNORED_TESTS - Lists of 'pytest -k' patterns to skip tests which are +# not expected to pass, e.g. requiring a database access. +# default: +# # The following variables can be read by ports and must not be modified: # # PYTHONBASE - The installation prefix of the chosen Python @@ -240,6 +256,13 @@ # PYDISTUTILS_INSTALLNOSINGLE # - Deprecated without replacement # +# The following variables may be set by the user: +# +# PYTEST_ENABLE_ALL_TESTS - Enable tests skipped by PYTEST_BROKEN_TESTS +# and PYTEST_IGNORED_TESTS. +# PYTEST_ENABLE_BROKEN_TESTS - Enable tests skipped by PYTEST_BROKEN_TESTS. +# PYTEST_ENABLE_IGNORED_TESTS - Enable tests skipped by PYTEST_IGNORED_TESTS. +# # MAINTAINER: python@FreeBSD.org .if !defined(_INCLUDE_USES_PYTHON_MK) @@ -256,7 +279,8 @@ # List all valid USE_PYTHON features here _VALID_PYTHON_FEATURES= allflavors autoplist concurrent cython cython_run \ distutils flavors noegginfo noflavors optsuffix \ - py3kplist pythonprefix + py3kplist pytest pytest4 pythonprefix unittest \ + unittest2 _INVALID_PYTHON_FEATURES= . for var in ${USE_PYTHON} . if empty(_VALID_PYTHON_FEATURES:M${var}) @@ -271,6 +295,9 @@ . for var in ${USE_PYTHON} _PYTHON_FEATURE_${var:C/=.*$//:tu}= ${var:C/.*=//:S/,/ /g} . endfor +. if defined(_PYTHON_FEATURE_PYTEST) && defined(_PYTHON_FEATURE_PYTEST4) +IGNORE= uses either USE_PYTHON=pytest or USE_PYTHON=pytest4, not both of them +. endif # distutils automatically generates flavors depending on the supported # versions. @@ -587,6 +614,32 @@ PYDISTUTILS_EGGINFO?= ${PYDISTUTILS_PKGNAME:C/[^A-Za-z0-9.]+/_/g}-${PYDISTUTILS_PKGVERSION:C/[^A-Za-z0-9.]+/_/g}-py${PYTHON_VER}.egg-info PYDISTUTILS_EGGINFODIR?=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} +# pytest support +. if defined(_PYTHON_FEATURE_PYTEST) +TEST_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}pytest>=0,1:devel/py-pytest@${PY_FLAVOR} +. elif defined(_PYTHON_FEATURE_PYTEST4) +TEST_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}pytest4>=0,1:devel/py-pytest4@${PY_FLAVOR} +. endif +. if defined(_PYTHON_FEATURE_PYTEST) || defined(_PYTHON_FEATURE_PYTEST4) +PYTEST_BROKEN_TESTS?= # empty +PYTEST_IGNORED_TESTS?= # empty +_PYTEST_SKIPPED_TESTS?= # empty +. if !defined(PYTEST_ENABLE_ALL_TESTS) +. if !defined(PYTEST_ENABLE_BROKEN_TESTS) +_PYTEST_SKIPPED_TESTS+= ${PYTEST_BROKEN_TESTS} +. endif +. if !defined(PYTEST_ENABLE_IGNORED_TESTS) +_PYTEST_SKIPPED_TESTS+= ${PYTEST_IGNORED_TESTS} +. endif +. endif # !defined(PYTEST_ENABLE_ALL_TESTS) +_PYTEST_FILTER_EXPRESSION= ${_PYTEST_SKIPPED_TESTS:C/^(.)/and not \1/:tW:C/^and //} +. endif # defined(_PYTHON_FEATURE_PYTEST) || defined(_PYTHON_FEATURE_PYTEST4) + +# unittest2 support +. if defined(_PYTHON_FEATURE_UNITTEST2) +TEST_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}unittest2>=0:devel/py-unittest2@${PY_FLAVOR} +. endif + . if !defined(_PYTHON_FEATURE_NOEGGINFO) && \ !defined(_PYTHON_FEATURE_AUTOPLIST) && \ defined(_PYTHON_FEATURE_DISTUTILS) && \ @@ -722,4 +775,26 @@ @(cd ${INSTALL_WRKSRC}; ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} ${PYDISTUTILS_SETUP} ${PYDISTUTILS_INSTALL_TARGET} ${PYDISTUTILS_INSTALLARGS}) . endif . endif # defined(_PYTHON_FEATURE_DISTUTILS) + +. if defined(_PYTHON_FEATURE_PYTEST) || defined(_PYTHON_FEATURE_PYTEST4) +. if !target(do-test) +do-test: + cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} -m pytest -k '${_PYTEST_FILTER_EXPRESSION}' -o addopts= -rs -v ${TEST_ARGS:MDESTDIR} +. endif +. endif # defined(_PYTHON_FEATURE_PYTEST) || defined(_PYTHON_FEATURE_PYTEST4) + +. if defined(_PYTHON_FEATURE_UNITTEST) +. if !target(do-test) +do-test: + cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} -m unittest -v ${TEST_ARGS:MDESTDIR} +. endif +. endif # defined(_PYTHON_FEATURE_UNITTEST) + +. if defined(_PYTHON_FEATURE_UNITTEST2) +. if !target(do-test) +do-test: + cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} -m unittest2 -v ${TEST_ARGS:MDESTDIR} +. endif +. endif # defined(_PYTHON_FEATURE_UNITTEST2) + .endif # defined(_POSTMKINCLUDED) && !defined(_INCLUDE_USES_PYTHON_POST_MK) diff --git a/databases/py-fakeredis/Makefile b/databases/py-fakeredis/Makefile --- a/databases/py-fakeredis/Makefile +++ b/databases/py-fakeredis/Makefile @@ -21,8 +21,8 @@ ${PYTHON_PKGNAMEPREFIX}pytest-cov>=0:devel/py-pytest-cov@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}pytest-mock>=0:devel/py-pytest-mock@${PY_FLAVOR} -USES= python:3.6+ pytest -USE_PYTHON= autoplist concurrent distutils +USES= python:3.6+ +USE_PYTHON= autoplist concurrent distutils pytest NO_ARCH= yes diff --git a/devel/py-funcsigs/Makefile b/devel/py-funcsigs/Makefile --- a/devel/py-funcsigs/Makefile +++ b/devel/py-funcsigs/Makefile @@ -12,14 +12,9 @@ LICENSE= APACHE20 LICENSE_FILE= ${WRKSRC}/LICENSE -TEST_DEPENDS= ${PYTHON_PKGNAMEPREFIX}unittest2>=0:devel/py-unittest2@${PY_FLAVOR} - USES= python:3.6+ -USE_PYTHON= autoplist concurrent distutils +USE_PYTHON= autoplist concurrent distutils unittest2 NO_ARCH= yes -do-test: - cd ${WRKSRC}/ && ${PYTHON_CMD} -m unittest2 -v - .include diff --git a/dns/py-idna/Makefile b/dns/py-idna/Makefile --- a/dns/py-idna/Makefile +++ b/dns/py-idna/Makefile @@ -13,11 +13,8 @@ LICENSE_FILE= ${WRKSRC}/LICENSE.md USES= python:3.5+ -USE_PYTHON= autoplist concurrent distutils +USE_PYTHON= autoplist concurrent distutils unittest NO_ARCH= yes -do-test: - cd ${WRKSRC} && ${PYTHON_CMD} -m unittest -v - .include