get test_ref_cycles to pass (#1539)

* get test_ref_cycles to pass

let objects die without gc.collect()
if you don't have cyclic references, there should be no need to call
gc.collect()

the usage of gc.collect() was causing pytest running with coverage to
crash on Python 3.7 / PySide2 5.12 / {Linux, Windows}.

* remove imports used only by the removed code
This commit is contained in:
pijyoi 2021-02-05 12:18:53 +08:00 committed by GitHub
parent f336ac2d91
commit cd914495ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 27 deletions

View File

@ -1,4 +1,3 @@
import gc
import weakref
try:
import faulthandler
@ -16,7 +15,6 @@ def test_getViewWidget():
view.addItem(item)
assert item.getViewWidget() is view
del view
gc.collect()
assert vref() is None
assert item.getViewWidget() is None
@ -30,7 +28,6 @@ def test_getViewWidget_deleted():
obj = pg.QtGui.QWidget()
view.setParent(obj)
del obj
gc.collect()
assert not pg.Qt.isQObjectAlive(view)
assert item.getViewWidget() is None

View File

@ -5,12 +5,9 @@ Test for unwanted reference cycles
"""
import pyqtgraph as pg
import numpy as np
import gc, weakref
import pytest
import weakref
app = pg.mkQApp()
skipreason = ('This test is failing on pyside and pyside2 for an unknown reason.')
def assert_alldead(refs):
for ref in refs:
assert ref() is None
@ -37,7 +34,6 @@ def mkrefs(*objs):
return [weakref.ref(obj) for obj in allObjs.values()]
@pytest.mark.skipif(pg.Qt.QT_LIB in {'PySide'}, reason=skipreason)
def test_PlotWidget():
def mkobjs(*args, **kwds):
w = pg.PlotWidget(*args, **kwds)
@ -55,7 +51,6 @@ def test_PlotWidget():
for i in range(5):
assert_alldead(mkobjs())
@pytest.mark.skipif(pg.Qt.QT_LIB in {'PySide', 'PySide2', 'PySide6'}, reason=skipreason)
def test_ImageView():
def mkobjs():
iv = pg.ImageView()
@ -63,12 +58,11 @@ def test_ImageView():
iv.setImage(data)
return mkrefs(iv, iv.imageItem, iv.view, iv.ui.histogram, data)
for i in range(5):
gc.collect()
assert_alldead(mkobjs())
@pytest.mark.skipif(pg.Qt.QT_LIB in {'PySide'}, reason=skipreason)
def test_GraphicsWindow():
def mkobjs():
w = pg.GraphicsWindow()

View File

@ -8,7 +8,6 @@ Distributed under MIT/X11 license. See license.txt for more information.
from ..Qt import QtCore, QtGui, QtWidgets, QT_LIB
from ..Point import Point
import sys, os
import warnings
from .FileDialog import FileDialog
from ..GraphicsScene import GraphicsScene
import numpy as np
@ -407,18 +406,3 @@ class GraphicsView(QtGui.QGraphicsView):
def dragEnterEvent(self, ev):
ev.ignore() ## not sure why, but for some reason this class likes to consume drag events
def _del(self):
try:
if self.parentWidget() is None and self.isVisible():
msg = "Visible window deleted. To prevent this, store a reference to the window object."
try:
warnings.warn(msg, RuntimeWarning, stacklevel=2)
except TypeError:
# warnings module not available during interpreter shutdown
pass
except RuntimeError:
pass
if sys.version_info[0] == 3 and sys.version_info[1] >= 4:
GraphicsView.__del__ = GraphicsView._del