diff --git a/test/test_c_ext.py b/test/test_c_ext.py index ce10fd4..06ba6d3 100644 --- a/test/test_c_ext.py +++ b/test/test_c_ext.py @@ -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 - 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 @@ -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*")