GH-94808: Cover PyOS_mystrnicmp
and PyOS_mystricmp
by artemmukhin · Pull Request #102469 · python/cpython (original) (raw)
I've found out that the tests were not executed because of the wrong naming.
Test_testcapi
only executes the test method if its built-in name starts with test_
and doesn't end with _code
:
class Test_testcapi(unittest.TestCase): |
---|
locals().update((name, getattr(_testcapi, name)) |
for name in dir(_testcapi) |
if name.startswith('test_') and not name.endswith('_code')) |
It is mentioned in the C API Tests paragraph to some extent:
Functions named
test_*
are used as tests directly
But at first reading, I got confused because in _testcapi/float.c
file, the test_
prefix is only used in the C function name:
static PyMethodDef test_methods[] = { |
---|
{"float_pack", test_float_pack, METH_VARARGS, NULL}, |
{"float_unpack", test_float_unpack, METH_VARARGS, NULL}, |
{NULL}, |
}; |
However, in contrast to my tests, these test methods are actually executed through test_float.py
:
class PackTests(unittest.TestCase): |
---|
def test_pack(self): |
self.assertEqual(_testcapi.float_pack(2, 1.5, BIG_ENDIAN), |
b'>\x00') |
I hope this investigation might help other first-time contributors.
@corona10 If you think it would be helpful to clarify this point in the devguide, please let me know, and I'll be happy to open a corresponding PR.