Skip to content

Commit

Permalink
test: Add test for ImportError due to undefined symbols in .so
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Jul 16, 2024
1 parent 5b80891 commit 9c131a0
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions test/test_c_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ def py_limited_api(request):

@pytest.fixture
def build_c_ext(pytester, py_limited_api):
def inner():
pytester.makefile(".c", test="""
def inner(code=""):
pytester.makefile(".c", test=f"""
#define PY_SSIZE_T_CLEAN
#include <Python.h>
static struct PyModuleDef testmodule = {
static struct PyModuleDef testmodule = {{
PyModuleDef_HEAD_INIT,
.m_name = "test",
.m_doc = NULL,
.m_size = -1,
.m_methods = NULL,
};
}};
extern void this_function_does_not_exist();
PyMODINIT_FUNC
PyInit_test(void)
{
{{
{code}
return PyModule_Create(&testmodule);
}
}}
""")
pytester.makepyfile(setup=f"""
from setuptools import setup, Extension
Expand All @@ -53,3 +56,16 @@ def test_c_ext(run, build_c_ext):
build_c_ext()
result = run("--ignore=setup.py")
result.assert_outcomes(passed=1)


def test_c_ext_undefined_symbol(run, build_c_ext):
build_c_ext(code="this_function_does_not_exist();")
result = run("--ignore=setup.py")
result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines([
"test.*::import-check*FAILED*",
"E*ImportError*test.*this_function_does_not_exist*",
])
# check whether we got nicely stripped traceback
#result.stdout.no_fnmatch_line("*/_pytest/*")
#result.stdout.no_fnmatch_line("*importlib*")

0 comments on commit 9c131a0

Please sign in to comment.