<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unit Testing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201757#M15520</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks that's a great tutorial! I hadn't seen it before.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Sep 2017 21:44:34 GMT</pubDate>
    <dc:creator>ClintonDow1</dc:creator>
    <dc:date>2017-09-26T21:44:34Z</dc:date>
    <item>
      <title>Unit Testing</title>
      <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201754#M15517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Our python script library is starting to get large and complex to the point that we are introducing unit testing to keep problems manageable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone had any experience creating Unit Tests for their python. How did you mock ArcGIS objects?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 20:56:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unit-testing/m-p/201754#M15517</guid>
      <dc:creator>Matrix_Solutions_Inc_Geomatics</dc:creator>
      <dc:date>2013-09-10T20:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Testing</title>
      <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201755#M15518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Our python script library is starting to get large and complex to the point that we are introducing unit testing to keep problems manageable.&lt;BR /&gt;Has anyone had any experience creating Unit Tests for their python. How did you mock ArcGIS objects?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have a specific example in mind?&amp;nbsp; I'm interested in this topic myself, but since the number of arcpy developers in our org is very small, the code base and testing we conduct is very project-focused and simply not much need to unit test a bunch of related libraries.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My limited unit testing is usually kept to small items and not related to GIS objects.&amp;nbsp; So things like string validation or variation tests might be done, but things such as database objects (cursors, rows of things, sql statements, etc...) are just not good candidates in my experience and I simply setup smaller functions/methods to perform a test (this allows me to clearly define connection and close operations to make sure things get killed properly).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 10:37:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unit-testing/m-p/201755#M15518</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-09-12T10:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Testing</title>
      <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201756#M15519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For arcpy functions, I use the mock library. Here is a basic example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;import&amp;nbsp;scriptRef&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;import unittest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;from mock import mock&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;class ScriptUnitTests(unittest.TestCase):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;@mock.patch('arcpy.da')&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp; &amp;nbsp;def test_when_starting_session_should_start_edtior(self, mock_da):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variables = " "&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;scriptRef.scriptMethod(variables)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mock_da.Editor.assert_called_with(variables)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 15px;"&gt;I also recommend this article for helpful arcpy testing strategies:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 15px;"&gt;&lt;A class="link-titled" href="http://notesfromthelifeboat.com/post/testing-arcpy-2/" title="http://notesfromthelifeboat.com/post/testing-arcpy-2/"&gt;Testing with ArcPy: Isolation and Mocking· Notes from the Lifeboat&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Sep 2017 18:57:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unit-testing/m-p/201756#M15519</guid>
      <dc:creator>deleted-user-st4HsVxccxgs</dc:creator>
      <dc:date>2017-09-21T18:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Testing</title>
      <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201757#M15520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks that's a great tutorial! I hadn't seen it before.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Sep 2017 21:44:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unit-testing/m-p/201757#M15520</guid>
      <dc:creator>ClintonDow1</dc:creator>
      <dc:date>2017-09-26T21:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unit Testing</title>
      <link>https://community.esri.com/t5/python-questions/unit-testing/m-p/201758#M15521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In general its much easier to test scripts when they have been heavily modularized. The .py file that the toolbox points to, or the .pyt file for Python toolboxes can both be very 'thin' in that they only need to handle the importing of arcpy and the parameter i/o, then the rest of the logic split across several modules which are imported. This makes testing those modules easier, as they can be separated into those which require arcpy and those that don't.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, rather than having a section of the script which processes each row in a feature class within a loop, break that logic out of the main script into an arcpy-bound function which takes a path to a table and list of fields, then generates rows from the table via an arcpy.da.cursor. This function can easily be mocked to return tuples,&amp;nbsp;because it can be called independently of the main script. This also allows you to easily debug this code in an IDE, since it can be run completely independently of the ArcGIS UI at that point.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Sep 2017 21:58:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unit-testing/m-p/201758#M15521</guid>
      <dc:creator>ClintonDow1</dc:creator>
      <dc:date>2017-09-26T21:58:42Z</dc:date>
    </item>
  </channel>
</rss>

