Skip to content

Commit cfcfe76

Browse files
committed
tests: support skipping
1 parent 21013d6 commit cfcfe76

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

tests/CMakeLists.txt

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ else()
1616
cmake_policy(VERSION 3.18)
1717
endif()
1818

19+
# Only needed for CMake < 3.5 support
20+
include(CMakeParseArguments)
21+
22+
# Filter out items; print an optional message if any items filtered
23+
#
24+
# Usage:
25+
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
26+
#
27+
function(PYBIND11_FILTER_TESTS LISTNAME)
28+
cmake_parse_arguments(ARG "" "MESSAGE" "" ${ARGN})
29+
set(PYBIND11_FILTER_TESTS_FOUND OFF)
30+
foreach(filename IN LISTS ARG_UNPARSED_ARGUMENTS)
31+
list(FIND ${LISTNAME} ${filename} FILE_FOUND)
32+
if(FILE_FOUND GREATER -1)
33+
list(REMOVE_AT PYBIND11_TEST_FILES ${FILE_FOUND})
34+
set(PYBIND11_FILTER_TESTS_FOUND ON)
35+
endif()
36+
endforeach()
37+
if(PYBIND11_FILTER_TESTS_FOUND AND ARG_MESSAGE)
38+
message(STATUS "${ARG_MESSAGE}")
39+
endif()
40+
endfunction()
41+
1942
# New Python support
2043
if(DEFINED Python_EXECUTABLE)
2144
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
@@ -65,7 +88,7 @@ set(PYBIND11_TEST_FILES
6588
test_eigen.cpp
6689
test_enum.cpp
6790
test_eval.cpp
68-
#AV this fails with PGI test_exceptions.cpp
91+
test_exceptions.cpp
6992
test_factory_constructors.cpp
7093
test_gil_scoped.cpp
7194
test_iostream.cpp
@@ -82,13 +105,12 @@ set(PYBIND11_TEST_FILES
82105
test_pickling.cpp
83106
test_pytypes.cpp
84107
test_sequences_and_iterators.cpp
85-
#AV this fails with PGI test_smart_ptr.cpp
108+
test_smart_ptr.cpp
86109
test_stl.cpp
87110
test_stl_binders.cpp
88111
test_tagbased_polymorphic.cpp
89112
test_union.cpp
90-
#AV this fails with PGI test_virtual_functions.cpp
91-
)
113+
test_virtual_functions.cpp)
92114

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

101-
# Skip test_async for Python < 3.5
102-
list(FIND PYBIND11_TEST_FILES test_async.cpp PYBIND11_TEST_FILES_ASYNC_I)
103-
if((PYBIND11_TEST_FILES_ASYNC_I GREATER -1) AND (PYTHON_VERSION VERSION_LESS 3.5))
104-
message(STATUS "Skipping test_async because Python version ${PYTHON_VERSION} < 3.5")
105-
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_ASYNC_I})
123+
if(PYTHON_VERSION VERSION_LESS 3.5)
124+
pybind11_filter_tests(PYBIND11_TEST_FILES test_async.cpp MESSAGE
125+
"Skipping test_async on Python 2")
126+
endif()
127+
128+
if(CMAKE_CXX_COMPILER_ID MATCHES "PGI")
129+
pybind11_filter_tests(
130+
PYBIND11_TEST_FILES test_exceptions.cpp test_smart_ptr.cpp test_virtual_functions.cpp MESSAGE
131+
"Skipping tests that do not support PGI compilers")
106132
endif()
107133

108134
string(REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES}")

tests/test_exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pytest
55

6-
from pybind11_tests import exceptions as m
7-
import pybind11_cross_module_tests as cm
6+
m = pytest.importorskip("pybind11_tests.exceptions")
7+
import pybind11_cross_module_tests as cm # noqa: E402
88

99

1010
def test_std_exception(msg):

tests/test_smart_ptr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# -*- coding: utf-8 -*-
22
import pytest
3-
from pybind11_tests import smart_ptr as m
4-
from pybind11_tests import ConstructorStats
3+
4+
m = pytest.importorskip("pybind11_tests.smart_ptr")
5+
6+
from pybind11_tests import ConstructorStats # noqa: E402
57

68

79
def test_smart_ptr(capture):

tests/test_virtual_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import env # noqa: F401
55

6-
from pybind11_tests import virtual_functions as m
7-
from pybind11_tests import ConstructorStats
6+
m = pytest.importorskip("pybind11_tests.virtual_functions")
7+
8+
from pybind11_tests import ConstructorStats # noqa: E402
89

910

1011
def test_override(capture, msg):

0 commit comments

Comments
 (0)