News for hackers. Stuff that matters.
Re:Running C unit tests with Pytest by haberman on Saturday February 12, 2022 @02:38PM (#30315603)
A notable downside that is not mentioned: the Python interpreter is far from Valgrind-clean. Valgrind is generally a powerful tool for debugging memory errors, but if you wrap your C code in Python, Valgrind will be so noisy as to be ineffective. Python startup is also very heavyweight; combined with the ~60x slowdown from Valgrind this is something you are going to notice.

The Python interpreter does not even use malloc()/free() directly by default; it layers its own memory allocator on top called PyMalloc (https://docs.python.org/3/c-api/memory.html#pymalloc). You can disable this by setting an environment variable (PYTHONMALLOC=malloc), but even then you will see many Valgrind warnings inside the Python interpreter itself.

Re:Running C unit tests with Pytest by p403n1x87 on Saturday February 12, 2022 @02:46PM (#30315668)
That's a good argument for keeping these kind of tests separate. Indeed Austin has dedicated Valgrind integration tests just for this reason.
Re:Running C unit tests with Pytest by wiredfool on Saturday February 12, 2022 @06:27PM (#30317416)
I’ve had success running valgrind on python code with a very small suppression list to cover all of the python interpreter issues (at least for safety, not leaks) and let me focus on the code.
Re:Running C unit tests with Pytest by cozzyd on Saturday February 12, 2022 @09:03PM (#30318396)
Is such a suppression list publicly available somewhere?
Re:Running C unit tests with Pytest by wiredfool on Sunday February 13, 2022 @04:43AM (#30320561)
https://github.com/python-pillow/docker-images/blob/main/ubu...

This docker image is what we’re using in CI to do memory safety checks against the pillow c extension.

Re:Running C unit tests with Pytest by cozzyd on Sunday February 13, 2022 @04:48AM (#30320597)
That is indeed very short! Thanks!