-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Segmentation fault on cv2 class inheritance #9738
Description
- a detailed description of the bug or problem you are having
- output of
pip listfrom the virtual environment you are using - pytest and operating system versions
- minimal example if possible
I think that I found a bug in the pytest module. Running the same code without pytest works properly. This is the minimal working example:
from cv2 import cv2
class KalmanFilter1(cv2.KalmanFilter):
def __init__(self):
super(KalmanFilter1, self).__init__()
pass
def test():
kf = KalmanFilter1()
def test2():
kf = KalmanFilter1()
if __name__ == "__main__":
kf = KalmanFilter1(None)
kf2 = KalmanFilter1(None)
Running python3 test.py works; running python3 -m pytest test.py produces following output:
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
collected 2 items
test.py ..Fatal Python error: Segmentation fault
Current thread 0x00007f21b26ac740 (most recent call first):
File "/usr/local/lib/python3.8/dist-packages/_pytest/terminal.py", line 1173 in _set_main_color
File "/usr/local/lib/python3.8/dist-packages/_pytest/terminal.py", line 1150 in _get_main_color
File "/usr/local/lib/python3.8/dist-packages/_pytest/terminal.py", line 619 in _write_progress_information_filling_space
File "/usr/local/lib/python3.8/dist-packages/_pytest/terminal.py", line 592 in pytest_runtest_logfinish
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265 in __call__
File "/usr/local/lib/python3.8/dist-packages/_pytest/runner.py", line 110 in pytest_runtest_protocol
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265 in __call__
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 348 in pytest_runtestloop
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265 in __call__
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 323 in _main
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 269 in wrap_session
File "/usr/local/lib/python3.8/dist-packages/_pytest/main.py", line 316 in pytest_cmdline_main
File "/usr/local/lib/python3.8/dist-packages/pluggy/_callers.py", line 39 in _multicall
File "/usr/local/lib/python3.8/dist-packages/pluggy/_manager.py", line 80 in _hookexec
File "/usr/local/lib/python3.8/dist-packages/pluggy/_hooks.py", line 265 in __call__
File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 162 in main
File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 185 in console_main
File "/usr/local/lib/python3.8/dist-packages/pytest/__main__.py", line 5 in <module>
File "/usr/lib/python3.8/runpy.py", line 87 in _run_code
File "/usr/lib/python3.8/runpy.py", line 194 in _run_module_as_main
Segmentation fault (core dumped)
Also worth noting is that the test sometimes (1 out of 5 times) finishes without errors, when removing test2().
I think this has something to do with the suplerclass cv2.KalmanFilter which is implemented in C. But it is still weird that no error occurs when running as a normal program.
The error occurred on Linux Mint 20.3 Cinnamon
Running the analog version of the code in the unittest module sometimes also produces this error, but it works properly in the majority of runs. Maybe this has nothing to do with pytest, but what is happening here?