[TIP] testing the creation of infrastructure

Mark Sienkiewicz sienkiew at stsci.edu
Tue Aug 30 09:13:50 PDT 2011


Joseph Heck wrote:
> I'm doing a lot of building infrastructure work right now, and I'm trying to create tests that I can run repeatedly from Jenkins (or name your CI server here). The nature of the tests is that they take a while - including long periods of waiting, and sometimes completely asynchronous calls in the midst of the process where you don't get an event or call back (i.e. need to poll to check status).
>
> I'd ideally like to use the Unittest module, just because I'm very familiar with the assertions and structures for writing tests, but I'm finding that I need a test running that does the tests sequentially, and ideally in a predictable order so that I don't have single def testSomething(): methods that are truly monstrous.
>   

I'm not sure I see the problem in detail, but I have two observations:

- Both nose and py.test run test functions in the order that you find 
them in the file. This gets you a predictable order.

def test_2():
assert False

def test_1():
assert False

This runs test_2, then test_1.


- It is fairly trivial to use a unittest2 assertion without using the 
rest of unittest:

import unittest2

class dummy_ut2( unittest2.TestCase ) : # not named test_something
__test__ = False # just in case
def runTest( wtf ) :
raise Exception('Should never be called')
xcmp = dummy_ut2()

def test_a() :
xcmp.assertAlmostEqual( 1.001, 1.002, places=4 )


IMHO, it owuld be


> I know this is the antithesis to getting tests to run faster - what I'm looking to codify are long running tests that I can use for regression and acceptance criteria.
>   

Well, running correctly is better than running fast, right? :)






More information about the testing-in-python mailing list