diff --git a/.travis.yml b/.travis.yml index e74a25066..8ce8f2b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ matrix: install: - > docker exec --tty "$containerid" apt-get -y --no-install-recommends install - python2.7-dev python-scipy libeigen3-dev + python2.7-dev python-pip python-setuptools python-scipy libeigen3-dev cmake make g++ - compiler: gcc-6 services: docker @@ -48,7 +48,7 @@ matrix: install: - > docker exec --tty "$containerid" apt-get -y --no-install-recommends install - python3.5-dev python3-scipy libeigen3-dev + python3.5-dev python3-pip python3-setuptools python3-scipy libeigen3-dev cmake make g++ # Documentation build: - os: linux diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d4db9032a..dbf64c46b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -58,6 +58,31 @@ if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) endforeach() endif() +# Make sure pytest is found or try to install it if it's not found +macro(pybind11_execute_python) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -m ${ARGN} OUTPUT_QUIET ERROR_QUIET + RESULT_VARIABLE pybind11_execute_python_error) +endmacro() + +if(NOT PYBIND11_PYTEST_FOUND) + pybind11_execute_python(pytest --version --noconftest) + if(pybind11_execute_python_error) + message(STATUS "Installing pytest using pip") + pybind11_execute_python(pip install pytest) + if(pybind11_execute_python_error) + message(STATUS "Installing pytest using pip --user (fallback)") + pybind11_execute_python(pip install --user pytest) + endif() + + pybind11_execute_python(pytest --version --noconftest) + if(pybind11_execute_python_error) + message(FATAL_ERROR "Running the tests requires pytest. Please install it manually.") + endif() + endif() + + set(PYBIND11_PYTEST_FOUND TRUE CACHE INTERAL "") +endif() + # A single command to compile and run the tests -add_custom_target(pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest +add_custom_target(pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest -rws DEPENDS pybind11_tests WORKING_DIRECTORY ${testdir})