Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
parallel = True
source =
tests

[paths]
source =
tests/
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ jobs:
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_BUILD_TYPE=Debug
-DPYBIND11_TEST_COVERAGE=ON
-DCMAKE_CXX_STANDARD=17
${{ matrix.args }}
${{ matrix.args2 }}
Expand All @@ -135,6 +137,9 @@ jobs:
- name: Python tests
run: cmake --build build2 --target pytest

- name: Upload to Codecov
run: codecov --token "${{ secrets.CODECOV_TOKEN }}" --name "${{ matrix.python }}-${{ matrix.runs-on }}-${{ matrix.args }}"

- name: C++ tests
# TODO: Figure out how to load the DLL on Python 3.8+
if: "!(runner.os == 'Windows' && (matrix.python == 3.8 || matrix.python == 3.9 || matrix.python == '3.10-dev'))"
Expand Down Expand Up @@ -273,7 +278,7 @@ jobs:
- uses: actions/checkout@v2

- name: Add wget and python3
run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev
run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev python3-pytest-cov

- name: Configure
shell: bash
Expand Down Expand Up @@ -308,7 +313,7 @@ jobs:

# tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND
- name: Install 🐍 3
run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy
run: apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y cmake git python3-dev python3-pytest python3-numpy python3-pytest-cov

- name: Configure
run: cmake -S . -B build -DPYBIND11_CUDA_TESTS=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
Expand All @@ -331,7 +336,7 @@ jobs:
# - uses: actions/checkout@v2
#
# - name: Add Python 3 and a few requirements
# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules
# run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules python3-pytest-cov
#
# - name: Install CMake with pip
# run: |
Expand Down Expand Up @@ -435,7 +440,7 @@ jobs:
- uses: actions/checkout@v1

- name: Add Python 3
run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev
run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev python3-pytest-cov

- name: Update pip
run: python3 -m pip install --upgrade pip
Expand Down
20 changes: 19 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ else()
cmake_policy(VERSION 3.18)
endif()

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
# Only needed for CMake < 3.5 support
include(CMakeParseArguments)

Expand Down Expand Up @@ -308,6 +311,10 @@ if(PYBIND11_CUDA_TESTS)
set_property(SOURCE ${PYBIND11_TEST_FILES} PROPERTY LANGUAGE CUDA)
endif()

set(PYBIND11_TEST_COVERAGE
OFF
CACHE BOOL "Collect test coverage for C++ and Python")

foreach(target ${test_targets})
set(test_files ${PYBIND11_TEST_FILES})
if(NOT "${target}" STREQUAL "pybind11_tests")
Expand Down Expand Up @@ -349,6 +356,11 @@ foreach(target ${test_targets})
target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_BOOST)
endif()

if(PYBIND11_TEST_COVERAGE AND NOT MSVC)
target_compile_options(${target} PRIVATE -coverage)
target_link_libraries(${target} PRIVATE -coverage)
endif()

# Always write the output file directly into the 'tests' directory (even on MSVC)
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
Expand Down Expand Up @@ -385,11 +397,17 @@ set(PYBIND11_TEST_PREFIX_COMMAND
""
CACHE STRING "Put this before pytest, use for checkers and such")

if(PYBIND11_TEST_COVERAGE)
set(PYBIND11_PYTEST_EXTRA_FLAGS "--cov=pybind11")
else()
set(PYBIND11_PYTEST_EXTRA_FLAGS "")
endif()

# A single command to compile and run the tests
add_custom_target(
pytest
COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest
${PYBIND11_ABS_PYTEST_FILES}
${PYBIND11_PYTEST_EXTRA_FLAGS} ${PYBIND11_ABS_PYTEST_FILES}
DEPENDS ${test_targets}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
USES_TERMINAL)
Expand Down
3 changes: 3 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
--extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010/
codecov>=2.0.5
coverage>=4.2
numpy==1.16.6; python_version<"3.6" and sys_platform!="win32"
numpy==1.18.0; platform_python_implementation=="PyPy" and sys_platform=="darwin" and python_version>="3.6"
numpy==1.19.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10"
pytest==4.6.9; python_version<"3.5"
pytest==6.1.2; python_version=="3.5"
pytest==6.2.1; python_version>="3.6"
pytest-cov
scipy==1.2.3; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version<"3.6"
scipy==1.5.4; (platform_python_implementation!="PyPy" or sys_platform=="linux") and python_version>="3.6" and python_version<"3.10"