<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Test Driven Developer - Python</title>
    <link>http://testdrivendeveloper.com/</link>
    <description>You got a TEST for that?</description>
    <language>en-us</language>
    <copyright>John E. Boal</copyright>
    <lastBuildDate>Tue, 07 Oct 2008 16:09:49 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>web_master1@TestDrivenDeveloper.com</managingEditor>
    <webMaster>web_master1@TestDrivenDeveloper.com</webMaster>
    <item>
      <trackback:ping>http://testdrivendeveloper.com/Trackback.aspx?guid=10a8368d-9191-4f9c-bc29-ca957bb111e5</trackback:ping>
      <pingback:server>http://testdrivendeveloper.com/pingback.aspx</pingback:server>
      <pingback:target>http://testdrivendeveloper.com/PermaLink,guid,10a8368d-9191-4f9c-bc29-ca957bb111e5.aspx</pingback:target>
      <dc:creator>John E. Boal</dc:creator>
      <wfw:comment>http://testdrivendeveloper.com/CommentView,guid,10a8368d-9191-4f9c-bc29-ca957bb111e5.aspx</wfw:comment>
      <wfw:commentRss>http://testdrivendeveloper.com/SyndicationService.asmx/GetEntryCommentsRss?guid=10a8368d-9191-4f9c-bc29-ca957bb111e5</wfw:commentRss>
      <title>More Tips for Unit Testing in Iron Python</title>
      <guid isPermaLink="false">http://testdrivendeveloper.com/PermaLink,guid,10a8368d-9191-4f9c-bc29-ca957bb111e5.aspx</guid>
      <link>http://TestDrivenDeveloper.com/2008/10/07/MoreTipsForUnitTestingInIronPython.aspx</link>
      <pubDate>Tue, 07 Oct 2008 16:09:49 GMT</pubDate>
      <description>&lt;div&gt;Do you ever wonder why there is an extra "False" printed at the end of each run for unit tests?&lt;br&gt;&lt;br&gt;&lt;font face="Courier New"&gt;C:\Code\sample&amp;gt;ipy UnitTests.py&lt;br&gt;.....&lt;br&gt;----------------------------------------------------------------------&lt;br&gt;Ran 5 tests in 0.395s&lt;br&gt;&lt;br&gt;OK&lt;br&gt;False&lt;/font&gt;&lt;br&gt;&lt;br&gt;It looks like there is an exit statement buried inside the unit test framework. We can eliminate the problem pretty easily with the addition of a try/except around the unit test execution. Here is the code to put at the end of your unit test script:&lt;br&gt;&lt;br&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;if&lt;/font&gt; __name__ &lt;font color="#0000ff"&gt;==&lt;/font&gt; '&lt;font color="#a9a9a9"&gt;__main__&lt;/font&gt;':&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;try&lt;/font&gt;:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unittest.main&lt;font color="#0000ff"&gt;()&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;except&lt;/font&gt; SystemExit:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;pass&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;This catches and eats the SystemExit exception, and runs without printing the "False" at the end of the execution:&lt;br&gt;&lt;br&gt;&lt;font face="Courier New"&gt;C:\Code\sample&amp;gt;ipy UnitTests.py&lt;br&gt;.....&lt;br&gt;----------------------------------------------------------------------&lt;br&gt;Ran 5 tests in 0.387s&lt;br&gt;&lt;br&gt;OK&lt;br&gt;&lt;/font&gt;&lt;br&gt;cheers!&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://testdrivendeveloper.com/aggbug.ashx?id=10a8368d-9191-4f9c-bc29-ca957bb111e5"/&gt;&lt;/div&gt;</description>
      <comments>http://testdrivendeveloper.com/CommentView,guid,10a8368d-9191-4f9c-bc29-ca957bb111e5.aspx</comments>
      <category>Python</category>
      <category>Testing</category>
      <category>Unit Tests</category>
    </item>
    <item>
      <trackback:ping>http://testdrivendeveloper.com/Trackback.aspx?guid=9c73a72b-9654-4976-83b5-e3f9b6b67e3f</trackback:ping>
      <pingback:server>http://testdrivendeveloper.com/pingback.aspx</pingback:server>
      <pingback:target>http://testdrivendeveloper.com/PermaLink,guid,9c73a72b-9654-4976-83b5-e3f9b6b67e3f.aspx</pingback:target>
      <dc:creator>John E. Boal</dc:creator>
      <wfw:comment>http://testdrivendeveloper.com/CommentView,guid,9c73a72b-9654-4976-83b5-e3f9b6b67e3f.aspx</wfw:comment>
      <wfw:commentRss>http://testdrivendeveloper.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9c73a72b-9654-4976-83b5-e3f9b6b67e3f</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Unit Testing in Python</title>
      <guid isPermaLink="false">http://testdrivendeveloper.com/PermaLink,guid,9c73a72b-9654-4976-83b5-e3f9b6b67e3f.aspx</guid>
      <link>http://TestDrivenDeveloper.com/2008/09/30/UnitTestingInPython.aspx</link>
      <pubDate>Tue, 30 Sep 2008 13:26:26 GMT</pubDate>
      <description>&lt;div&gt;&lt;P&gt;I have been using IronPython lately, and am having a good time testing code with its built-in unit test framework. Here is a brief example of how to write some unit tests for &lt;a target=_ipy href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/a&gt; (or CPython if that's your flavor). These unit tests&amp;nbsp;leverage the "unittest" module available in Python 2.2 and above.&lt;/P&gt;
&lt;P&gt;Here is a short test class:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; TestCode:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; localInt = &lt;FONT color=#ff0000&gt;1&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @classmethod&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;def&lt;/FONT&gt; &lt;FONT color=#ff1493&gt;Method1&lt;/FONT&gt;(self):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;return&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;100&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;def&lt;/FONT&gt; &lt;FONT color=#ff1493&gt;Method2&lt;/FONT&gt;(self, a, b):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.localInt = a * b&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here are&amp;nbsp;some sample&amp;nbsp;unit tests for it, using the unittest framework:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;import&lt;/FONT&gt; unittest&lt;BR&gt;&lt;FONT color=#0000ff&gt;class&lt;/FONT&gt; UnitTests(unittest.TestCase):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;def&lt;/FONT&gt; &lt;FONT color=#ff1493&gt;testMethod1&lt;/FONT&gt;(self):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut = TestCode()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; actual = cut.Method1()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.assertEqual(&lt;FONT color=#ff0000&gt;100&lt;/FONT&gt;, actual)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;def&lt;/FONT&gt; &lt;FONT color=#ff1493&gt;teststaticInt&lt;/FONT&gt;(self):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.assertEqual(&lt;FONT color=#ff0000&gt;1&lt;/FONT&gt;, TestCode.localInt)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#0000ff&gt;def&lt;/FONT&gt; &lt;FONT color=#ff1493&gt;testMethod2&lt;/FONT&gt;(self):&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut = TestCode()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cut.Method2(&lt;FONT color=#ff0000&gt;7&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;4&lt;/FONT&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.assertEqual(&lt;FONT color=#ff0000&gt;28&lt;/FONT&gt;, cut.localInt)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;if&lt;/FONT&gt; __name__ == '&lt;FONT color=#808080&gt;__main__&lt;/FONT&gt;':&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unittest.main()&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This example should illustrate that we can write some unit tests for our Python code fairly easily and quickly. It's nice to have a built-in framework for unit testing. There is also a "doctest" module available for doing more like system testing. I am pretty new to Python, so I haven't got examples of this as yet.&lt;/P&gt;
&lt;P&gt;If anyone has any suggestions on tools&amp;nbsp;or experience with &lt;A href="http://blogs.msdn.com/aaronmar/archive/2006/02/16/533273.aspx"&gt;integration with Visual Studio&lt;/A&gt;&amp;nbsp;those comments would be appreciated.&lt;/P&gt;&lt;img width="0" height="0" src="http://testdrivendeveloper.com/aggbug.ashx?id=9c73a72b-9654-4976-83b5-e3f9b6b67e3f"/&gt;&lt;/div&gt;</description>
      <comments>http://testdrivendeveloper.com/CommentView,guid,9c73a72b-9654-4976-83b5-e3f9b6b67e3f.aspx</comments>
      <category>TDD</category>
      <category>Testing</category>
      <category>Tools</category>
      <category>Python</category>
    </item>
  </channel>
</rss>