matplotlib / pytest-mpl

A pytest plugin to facilitate image comparison for Matplotlib figures
Other
244 stars 47 forks source link

Python 3.12: pytest seg faults with mpl tests #227

Closed bje- closed 4 months ago

bje- commented 4 months ago

I am testing my package on Python 3.12. The testsuite uses pytest-mpl. When running the following minimised test case, pytest (well, presumably, the Python interpreter) segfaults. Any test that does not use mpl decorators runs fine.

import pytest
import unittest
import matplotlib.pyplot as plt

class TestUtils(unittest.TestCase):

    @pytest.mark.mpl_image_compare
    def test_figure_1(self):
        return plt.figure()
bje- commented 4 months ago

I ran python3.12 under GDB and ran -m pytest testcase.py and got this backtrace:

Thread 1 "python3.12" received signal SIGSEGV, Segmentation fault.
0x00000000005333f0 in _PyInterpreterState_GET () at ../Include/internal/pycore_pystate.h:133
(gdb) bt
#0  0x00000000005333f0 in _PyInterpreterState_GET () at ../Include/internal/pycore_pystate.h:133
#1  get_state () at ../Objects/obmalloc.c:866
#2  _PyObject_Free (p=0x20bf0b0, ctx=0x0) at ../Objects/obmalloc.c:1850
#3  PyMem_Free (ptr=0x20bf0b0) at ../Objects/obmalloc.c:732
#4  0x00007fffe5921839 in sip_api_free (mem=<optimised out>) at ../../../../sip/siplib/siplib.c:2162
#5  0x00007fffe591d61d in sipOMFinalise (om=om@entry=0x7fffe593fec0 <cppPyMap>)
    at ../../../../sip/siplib/objmap.c:69
#6  0x00007fffe5921a2f in finalise () at ../../../../sip/siplib/siplib.c:2064
#7  0x00000000004630c1 in call_ll_exitfuncs (runtime=<optimised out>) at ../Python/pylifecycle.c:3046
#8  Py_FinalizeEx () at ../Python/pylifecycle.c:2005
#9  0x0000000000657a9e in Py_RunMain () at ../Modules/main.c:711
#10 0x0000000000610acd in Py_BytesMain (argc=<optimised out>, argv=<optimised out>) at ../Modules/main.c:763
#11 0x00007ffff7c29d90 in __libc_start_call_main
     (main=main@entry=0x610a10 <main>, argc=argc@entry=4, argv=argv@entry=0x7fffffffe2b8)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#12 0x00007ffff7c29e40 in __libc_start_main_impl
     (main=0x610a10 <main>, argc=4, argv=0x7fffffffe2b8, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fffffffe2a8) at ../csu/libc-start.c:392
#13 0x0000000000610945 in _start ()
bje- commented 4 months ago

I figure this is very likely to be a Python interpreter bug, so filed https://github.com/python/cpython/issues/120387 as well.

bje- commented 4 months ago

pytest no longer implicated :-)

bje- commented 4 months ago

Closing.