Search code examples
pythonnosenosetests

how to handle time-consuming tests


I have tests which have a huge variance in their runtime. Most will take much less than a second, some maybe a few seconds, some of them could take up to minutes.

Can I somehow specify that in my Nosetests?

In the end, I want to be able to run only a subset of my tests which take e.g. less than 1 second (via my specified expected runtime estimate).


Solution

  • Have a look at this write up about attribute plugin for nose tests, where you can manually tag tests as @attr('slow') and @attr('fast'). You can tun nosetests -a '!slow' afterward to run your tests quickly.

    It would be great if you can do it automatically, but I'm afraid that you would have to write additional code to do it on the fly. If you are into rapid development, I would run the nose with xunit xml output enabled (which tracks the runtime of each test). Your test module can dynamically read in your xml output file from previous runs and set attribute settings for tests accordingly to filter out quick tests. This way you do not have to do it manually, alas with more work (and you have to run all tests at least once).