[Qgis-developer] Changes to vector layers persist between python integration tests.
John Stevenson
john.stevenson at thinkwhere.com
Mon Jul 4 09:21:05 PDT 2016
Hi,
I am having trouble with integration tests that I am writing in a Python plugin. The tests run correctly one at a time, but when I run them together only the first test works correctly. It seems that changes it makes to the database are still present in the later tests. How can I make sure that the vector layer / database is fully reset between tests?
My tests are based on unittest.TestCase. The QGIS app is started with QGISAPP.initQGIS() as in the main QGIS tests and a Mock iface is used.
In the setUp, I make a temporary copy of a template spatialite file and run an SQL script on it to add features and other data. I connect to the database and store a reference to it (self.db). Then I load one of the tables as a QgsVectorLayer and store a reference to it (self.esu).
The first test uses self.esu.dataProvider().deleteFeatures() to remove features, the second uses self.esu.dataProvider().addFeatures() to add features. They check that the features have been added and that other database changes have been made.
The teardown contains the following:
if self.db: # Just in case self.db doesn't get set
self.db.close()
del self.db
QSqlDatabase.removeDatabase('integration_testing')
self.esu = None
reg = QgsMapLayerRegistry.instance()
reg.removeAllMapLayers()
reg.clearAllLayerCaches()
if os.path.exists(self.test_db_path):
os.remove(self.test_db_path)
I thought that this would be enough to reset any references to the vector layer, but if I delete a feature in the first test, it is still gone when I run the second test. Is QGIS holding any other references to the layers that I have missed?
Cheers
John
John Stevenson
Senior Developer
[cid:image2a0dbf.PNG at 4f0f9f2e.48a467c6]<http://www.thinkwhere.com>
t: 01786 476060 (Office)
t: 01786 476093 (Direct Dial)
w:www.thinkwhere.com<http://www.thinkwhere.com>
Glendevon House
Castle Business Park
Stirling FK9 4TZ
[cid:image33abae.PNG at 3495c8f4.468535fe]<https://twitter.com/thinkWhere1> [cid:imagea91387.PNG at 4d22f1ca.4db4dc83] <http://www.linkedin.com/company/1509510?trk=companies_home_ycp_logo_forth-valley-gis>
This email and its attachments are private and confidential. If you believe you have received this email in error, please contact the sender immediately on 01786 476060. If you are not the intended recipient, you may not rely on, use or disclose this email or any attachments in any way.
thinkWhere Limited does not accept any liability for any damage that may be caused to the recipient's system or data by this email or any attachments. Please note that our email system may be subject to random monitoring by us. This Company accepts no liability for personal emails.
thinkWhere is a limited company registered in Scotland with Registered Number SC315349 and having its Registered Office at Glendevon House, Castle Business Park, Stirling, FK9 4TZ.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160704/a7b0f686/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image2a0dbf.PNG
Type: image/png
Size: 7004 bytes
Desc: image2a0dbf.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160704/a7b0f686/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image33abae.PNG
Type: image/png
Size: 3618 bytes
Desc: image33abae.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160704/a7b0f686/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imagea91387.PNG
Type: image/png
Size: 3751 bytes
Desc: imagea91387.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160704/a7b0f686/attachment-0005.png>
More information about the Qgis-developer
mailing list