Repository: pyqtgraph/pyqtgraph

Issue:
Warnings output for visible windows after test functions run
When running the tests (I think as of merging #942), I get the following:

```
============================================================================================= warnings summary =============================================================================================
pyqtgraph/exporters/tests/test_svg.py::test_plotscene
pyqtgraph/graphicsItems/tests/test_AxisItem.py::test_AxisItem_stopAxisAtTick
pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py::test_ErrorBarItem_defer_data
pyqtgraph/graphicsItems/tests/test_PlotCurveItem.py::test_PlotCurveItem
pyqtgraph/graphicsItems/tests/test_PlotDataItem.py::test_clipping
  /home/kenny/src/pyqtgraph/.venv-pyqt5/lib/python3.7/site-packages/_pytest/python.py:165: RuntimeWarning: Visible window deleted. To prevent this, store a reference to the window object.
    testfunction(**testargs)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
============================================================================= 50 passed, 5 skipped, 5 warnings in 9.77 seconds =============================================================================
Exception ignored in: <function GraphicsView._del at 0x7f8a7df8bc20>
Traceback (most recent call last):
  File "/home/kenny/src/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 414, in _del
TypeError: 'NoneType' object is not callable
```

The `TypeError` is happening because `warnings.warn` is not available in some circumstances [[ref]](https://bugs.python.org/issue29174).

I think we just need to make sure any windows are closed at the end of the test functions so the warning isn't thrown during the tests. There aren't that many. The `TypeError` is kind of confusing so maybe we could catch that let it go in `GraphicsView._del` as well.


Discussion:

Resolving patch:
diff --git a/pyqtgraph/widgets/GraphicsView.py b/pyqtgraph/widgets/GraphicsView.py
--- a/pyqtgraph/widgets/GraphicsView.py
+++ b/pyqtgraph/widgets/GraphicsView.py
@@ -411,7 +411,11 @@ 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."
-                warnings.warn(msg, RuntimeWarning, stacklevel=2)
+                try:
+                    warnings.warn(msg, RuntimeWarning, stacklevel=2)
+                except TypeError:
+                    # warnings module not available during interpreter shutdown
+                    pass
         except RuntimeError:
             pass
 


Test patch:
diff --git a/pyqtgraph/exporters/tests/test_svg.py b/pyqtgraph/exporters/tests/test_svg.py
--- a/pyqtgraph/exporters/tests/test_svg.py
+++ b/pyqtgraph/exporters/tests/test_svg.py
@@ -28,6 +28,7 @@ def test_plotscene():
     ex.export(fileName=tempfilename)
     # clean up after the test is done
     os.unlink(tempfilename)
+    w.close()
 
 def test_simple():
     tempfilename = tempfile.NamedTemporaryFile(suffix='.svg').name
diff --git a/pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py
--- a/pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py
+++ b/pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py
@@ -71,6 +71,8 @@ def test_ViewBox():
     size1 = QRectF(0, h, w, -h)
     assertMapping(vb, view1, size1)
 
+    win.close()
+
 
 skipreason = "Skipping this test until someone has time to fix it."
 @pytest.mark.skipif(True, reason=skipreason)
diff --git a/pyqtgraph/graphicsItems/tests/test_AxisItem.py b/pyqtgraph/graphicsItems/tests/test_AxisItem.py
--- a/pyqtgraph/graphicsItems/tests/test_AxisItem.py
+++ b/pyqtgraph/graphicsItems/tests/test_AxisItem.py
@@ -28,3 +28,5 @@ def test_left(p, axisSpec, tickSpecs, textSpecs):
     monkeypatch.setattr(left, "drawPicture", test_left)
 
     plot.show()
+    app.processEvents()
+    plot.close()
diff --git a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py
--- a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py
+++ b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py
@@ -35,3 +35,5 @@ def test_ErrorBarItem_defer_data():
     r_clear_ebi = plot.viewRect()
 
     assert r_clear_ebi == r_no_ebi
+
+    plot.close()
diff --git a/pyqtgraph/graphicsItems/tests/test_PlotCurveItem.py b/pyqtgraph/graphicsItems/tests/test_PlotCurveItem.py
--- a/pyqtgraph/graphicsItems/tests/test_PlotCurveItem.py
+++ b/pyqtgraph/graphicsItems/tests/test_PlotCurveItem.py
@@ -27,7 +27,8 @@ def test_PlotCurveItem():
     
     c.setData(data, connect=np.array([1,1,1,0,1,1,0,0,1,0,0,0,1,1,0,0]))
     assertImageApproved(p, 'plotcurveitem/connectarray', "Plot curve with connection array.")
-    
+
+    p.close()
 
 
 if __name__ == '__main__':
diff --git a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py
--- a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py
+++ b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py
@@ -86,3 +86,5 @@ def test_clipping():
 
         assert xDisp[0] <= vr.left()
         assert xDisp[-1] >= vr.right()
+
+    w.close()