Skip to content

Commit

Permalink
tests: support skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Sep 9, 2020
1 parent 21013d6 commit e47625b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
44 changes: 35 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ else()
cmake_policy(VERSION 3.18)
endif()

# Only needed for CMake < 3.5 support
include(CMakeParseArguments)

# Filter out items; print an optional message if any items filtered
#
# Usage:
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
#
function(PYBIND11_FILTER_TESTS LISTNAME)
cmake_parse_arguments(ARG "" "MESSAGE" "" ${ARGN})
set(PYBIND11_FILTER_TESTS_FOUND OFF)
foreach(filename IN LISTS ARG_UNPARSED_ARGUMENTS)
list(FIND ${LISTNAME} ${filename} FILE_FOUND)
if(FILE_FOUND GREATER -1)
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_ASYNC_I})
set(PYBIND11_FILTER_TESTS_FOUND ON)
endif()
endforeach()
if(PYBIND11_FILTER_TESTS_FOUND AND ARG_MESSAGE)
message(STATUS "${ARG_MESSAGE}")
endif()
endfunction()

# New Python support
if(DEFINED Python_EXECUTABLE)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
Expand Down Expand Up @@ -65,7 +88,7 @@ set(PYBIND11_TEST_FILES
test_eigen.cpp
test_enum.cpp
test_eval.cpp
#AV this fails with PGI test_exceptions.cpp
test_exceptions.cpp
test_factory_constructors.cpp
test_gil_scoped.cpp
test_iostream.cpp
Expand All @@ -82,13 +105,12 @@ set(PYBIND11_TEST_FILES
test_pickling.cpp
test_pytypes.cpp
test_sequences_and_iterators.cpp
#AV this fails with PGI test_smart_ptr.cpp
test_smart_ptr.cpp
test_stl.cpp
test_stl_binders.cpp
test_tagbased_polymorphic.cpp
test_union.cpp
#AV this fails with PGI test_virtual_functions.cpp
)
test_virtual_functions.cpp)

# Invoking cmake with something like:
# cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" ..
Expand All @@ -98,11 +120,15 @@ if(PYBIND11_TEST_OVERRIDE)
set(PYBIND11_TEST_FILES ${PYBIND11_TEST_OVERRIDE})
endif()

# Skip test_async for Python < 3.5
list(FIND PYBIND11_TEST_FILES test_async.cpp PYBIND11_TEST_FILES_ASYNC_I)
if((PYBIND11_TEST_FILES_ASYNC_I GREATER -1) AND (PYTHON_VERSION VERSION_LESS 3.5))
message(STATUS "Skipping test_async because Python version ${PYTHON_VERSION} < 3.5")
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_ASYNC_I})
if(PYTHON_VERSION VERSION_LESS 3.5)
pybind11_filter_tests(PYBIND11_TEST_FILES test_async.cpp MESSAGE
"Skipping test_async on Python 2")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "PGI")
pybind11_filter_tests(
PYBIND11_TEST_FILES test_exceptions.cpp test_smart_ptr.cpp test_virtual_functions.cpp MESSAGE
"Skipping tests that do not support PGI compilers")
endif()

string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pytest

from pybind11_tests import exceptions as m
import pybind11_cross_module_tests as cm
m = pytest.importorskip("pybind11_tests.exceptions")
import pybind11_cross_module_tests as cm # noqa: E402


def test_std_exception(msg):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_smart_ptr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from pybind11_tests import smart_ptr as m
from pybind11_tests import ConstructorStats

m = pytest.importorskip("pybind11_tests.smart_ptr")

from pybind11_tests import ConstructorStats # noqa: E402


def test_smart_ptr(capture):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_virtual_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import env # noqa: F401

from pybind11_tests import virtual_functions as m
from pybind11_tests import ConstructorStats
m = pytest.importorskip("pybind11_tests.virtual_functions")

from pybind11_tests import ConstructorStats # noqa: E402


def test_override(capture, msg):
Expand Down

0 comments on commit e47625b

Please sign in to comment.