<div dir="ltr">OK,<div>So I know a few weeks ago there was a multiplatform related question, but mine is a bit different.</div><div><br></div><div>I&#39;m working on a project that has platform specific code in its working tree.</div>

<div>No matter what are the reasons, but currently in the same project tree there is platform specific code for several platforms side by side, and it currently can&#39;t be separated to different trees.</div><div><br></div>

<div>Now, about the unit-tests: pretty simple, each unit-test that can run only on a specific platform, raises a SkipTest in case you try running it on a different one (similar to what was suggested here a few weeks back).</div>

<div>Also, notice that some unit-tests may be in a platform specific package, but can actually run on all packages (because of mocks).</div><div><br></div><div>Great.</div><div><br></div><div>Now,</div><div>I want to be able to run all tests in my project with nose by running nosetests recursively on the root directory.</div>

<div>What&#39;s the problem with that?</div><div><br></div><div>The problem is that some of my __init__.py of the windows specific code, imports win32api, which exists only in windows.</div><div>Now from what I could understand, when nose is given a directory rather than a list of tests, it tries finding tests in all the packages recursively, and in the process it actually imports all __init__.py of modules, including the ones that are trying to import other platform specific stuff.</div>

<div><br></div><div>This is a problem, because there are no tests to skip here, and I end up getting an Error in my test-suite that isn&#39;t actually connected to a test.</div><div><br></div><div>Now, the way I see handling this right now, is avoiding importing stuff in __init__.py of packages, and either insert it into the function definitions, or to other .py files that are imported only explicitly and not from other __init__.py</div>

<div>I must say I&#39;m not really crazy about this solution.</div><div><br></div><div>Other solutions I thought of is to separate my code to different working trees and run on them (which is a big problem currently),</div>

<div>Or using something like --exclude=windows in nose, but this is bad because under windows there are unit tests that can be ran on any platform (because of mocks).</div><div><br></div><div>I was wondering if any of you can think of a better way to solve this annoying problem.</div>

<div><br></div><div>Thanks!</div><div>Yoni.</div><div><br></div></div>