It seems that you are right; but since I want to avoid static magic in the device handler, I think I&#39;ll have to shuffle the Java around a bit.<br><br>Thanks,<br>fredrik<br><br>Den söndagen den 31:e juli 2011 skrev Michael Foord&lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;:<br>
&gt; On 31 Jul 2011, at 11:23, Fredrik Håård wrote:<br>&gt;&gt;<br>&gt;&gt; Hi all (and thanks for the pizza! =),<br>&gt;&gt;<br>&gt;&gt; I&#39;d like to set up a test suite for an embedded J2ME application. Most of the code is cleanly separated from the platform since it runs on multiple platforms, and I wanted to use Jython to replace the platform-specific parts and run both unit and scenario testing on the common parts.<br>
&gt;&gt;<br>&gt;&gt; However, naive replacement of the class definitions does not seem to work, and trying to use mock to patch a java class like this:<br>&gt;&gt;<br>&gt;&gt; with mock.patch(&#39;my.device.DeviceHandler&#39;) as devicehandler:<br>
&gt;&gt;<br>&gt;&gt; i get:<br>&gt;&gt;<br>&gt;&gt; AttributeError: &#39;javapackage&#39; object has no attribute &#39;DeviceHandler&#39;<br>&gt;&gt;<br>&gt;&gt; Is it possible to get the behavior I want?<br>&gt;<br>&gt;<br>
&gt; I don&#39;t use python, but I assume that in Jython you can&#39;t replace arbitrary attributes on modules written in Java - just as you can&#39;t replace arbitrary attributes on modules written in C on CPython.<br>&gt;<br>
&gt; A way round this would be to import &#39;DeviceHandler&#39; into your module (instead of accessing it as &#39;my.device.DeviceHandler&#39; just use DeviceHandler). Then you can just patch &#39;DeviceHandler&#39; in the module you use it rather than having to patch it on the package that contains it.<br>
&gt;<br>&gt; All the best,<br>&gt;<br>&gt; Michael Foord<br>&gt;<br>&gt; --<br>&gt; <a href="http://www.voidspace.org.uk/">http://www.voidspace.org.uk/</a><br>&gt;<br>&gt;<br>&gt; May you do good and not evil<br>&gt; May you find forgiveness for yourself and forgive others<br>
&gt; May you share freely, never taking more than you give.<br>&gt; -- the sqlite blessing<br>&gt; <a href="http://www.sqlite.org/different.html">http://www.sqlite.org/different.html</a><br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>
&gt;<br>&gt;<br>&gt;<br><br>-- <br>/f<br><br>I reject your reality and substitute my own.<div><span style="font-family:anivers-1, anivers-2, sans-serif;color:rgb(216, 118, 0)"><a href="http://courteous.ly/yp3Zgd" style="color:inherit;text-decoration:underline" target="_blank">http://courteous.ly/yp3Zgd</a></span></div>
<br>