IronPython & NUnit - Updated For NUnit 2.4

Someone recently sent me an email letting me know my NUnit "support" for IronPython project only targeted NUnit 2.2 and was a little out of date.

(For those not sure what I'm talking about - perhaps take a look back at these posts (12) from October of 2006)

I didn't realise anyone was actually using it - but I see it's being linked too from the IronPython cookbook, so I decided to take half an hour and update it to target NUnit 2.4 - I left it targeting IronPython 1.1 however instead of 2.0 (IronPython users should be able to handle that task if required).

The usage changes a little from NUnit 2.2 to 2.4, instead of deriving your tests from a custom TestSuite class you now just annotate an empty class with some attributes... makes everything a little cleaner as your project doesn't need to reference IronPython etc. any more.

[PythonSuite, Script(FileName = "MyPythonFixture.py")] public class MyPythonSuite { }

The python files are embedded resources by default (though it's a minor code change to support external python files as well) - you can include multiple Script attributes for a single suite as well, if required.

If you want to dynamically include python resource files based on their content i.e. all embedded resources with a first line containing "#test" then you would do this:

[PythonSuite(DiscoverEmbeddedResources = true, DiscoveryKey = "#test")] public class DynamicPythonSuite { }

The project is now split into two assemblies.
  • IronPythonTest.Addin
  • IronPythonTest.Framework


The Addin assembly needs to be installed into your NUnit 2.4 add-ins directory i.e. C:Program Files (x86)TestDriven.NET 2.0NUnit2.4addins - you will need to place the IronPython assemblies in there as well if they're not registered in the
GAC.

Only the framework assembly needs to be referenced in your project so you can have access to the PythonSuite and Script attributes.

And that's about it, all other questions should be answered in the posts from 2006, or just leave a comment on this post if you have any trouble.

Code can be downloaded from here.

Written on April 13, 2008