<html dir="ltr">
<head>
<!-- Template generated by Exclaimer Mail Disclaimers on 05:21:05 Monday, 4 July 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">P.414e7b50-9f91-49ff-842d-fa8ec507eb62 {
MARGIN: 0cm 0cm 0pt
}
LI.414e7b50-9f91-49ff-842d-fa8ec507eb62 {
MARGIN: 0cm 0cm 0pt
}
DIV.414e7b50-9f91-49ff-842d-fa8ec507eb62 {
MARGIN: 0cm 0cm 0pt
}
TABLE.414e7b50-9f91-49ff-842d-fa8ec507eb62Table {
MARGIN: 0cm 0cm 0pt
}
DIV.Section1 {
page: Section1
}
</style><style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,<br>
<br>
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?<br>
<br>
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.<br>
<br>
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).<br>
<br>
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.<br>
<br>
The teardown contains the following:<br>
<br>
if self.db: # Just in case self.db doesn't get set<br>
self.db.close()<br>
del self.db<br>
QSqlDatabase.removeDatabase('integration_testing')<br>
<br>
self.esu = None<br>
reg = QgsMapLayerRegistry.instance()<br>
reg.removeAllMapLayers()<br>
reg.clearAllLayerCaches()<br>
<br>
if os.path.exists(self.test_db_path):<br>
os.remove(self.test_db_path)<br>
<br>
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?<br>
<br>
Cheers<br>
John<br>
</div>
<br>
<table class="414e7b50-9f91-49ff-842d-fa8ec507eb62Table" borderColor="black" cellspacing="0" cols="1" cellpadding="0" width="450" border="0">
<tbody>
<tr>
<td>
<p><span style="font-family:Arial; color: #009F94; font-weight: bold; ">John Stevenson</span><br>
<span style="font-family:Arial; font-size:x-small; ">Senior Developer</span> </p>
</td>
<td style="PADDING-BOTTOM: 5px; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px">
<p class="414e7b50-9f91-49ff-842d-fa8ec507eb62"><a href="http://www.thinkwhere.com"><img id="IMG1" border="0" align="right" src="cid:image2a0dbf.PNG@4f0f9f2e.48a467c6"></a></p>
</td>
</tr>
<tr>
<td>
<p><font size="2" face="Arial"><font color="#009f94">t:</font> 01786 476060 (Office)<br>
<font color="#009f94">t:</font> 01786 476093 (Direct Dial)<br>
<font color="#009f94">w:</font><a href="http://www.thinkwhere.com">www.thinkwhere.com</a></font>
</p>
</td>
<td style="PADDING-BOTTOM: 5px; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px">
<p align="right"><font size="2" face="Arial">Glendevon House<br>
Castle Business Park<br>
Stirling FK9 4TZ</font></p>
</td>
</tr>
<tr>
<td><a href="https://twitter.com/thinkWhere1"><img id="IMG1" border="0" align="left" src="cid:image33abae.PNG@3495c8f4.468535fe"></a>
<a href="http://www.linkedin.com/company/1509510?trk=companies_home_ycp_logo_forth-valley-gis">
<img id="IMG1" border="0" align="left" src="cid:imagea91387.PNG@4d22f1ca.4db4dc83"></a>
</td>
<td style="PADDING-BOTTOM: 5px; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px">
</td>
</tr>
</tbody>
</table>
<br>
<p align="justify"><font color="#7f7f7f" size="1" face="Verdana">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.<br>
<br>
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.<br>
<br>
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.
</p>
<br>
</font>
<p></p>
<p></p>
<p></p>
</body>
</html>