nosetest is the default test framework in Turbogeras 2.0. The application has a module that initialise the database. I use mysql for my development and production environment and websetup works fine, but nosetest uses sqlite on memory and when it tries to initialise the DB sends an error:

TypeError: SQLite Date, Time, and DateTime types only accept Python datetime objects as input.

I've detected when this happens and is in the import fase:

csvreader = csv.reader(open('res/products.csv'), delimiter=",", quotechar="'")
for row in csvreader:
    p = model.Product(row[1], row[2], row[3], row[4] + ".jpg")
    # Even tried to convert the date to a sqlalchemy type
    # need to put a conditional here, when testing I don't care this date
    import sqlalchemy
    dateadded = sqlalchemy.types.DateTime(row[5])
    p.dateAdded = dateadded
    p.brand_id = row[6]
    p.code = row[3]

    ccat = model.DBSession.query(model.Category)\
        .filter([8]) + 3).one()


    p.normalPrice = row[9]
    p.specialPrice = row[10]
    p.discountPrice = row[11]


How can I tell when nosetest is running? I've try:

if globals().has_key('ModelTest'):


if vars().has_key('ModelTest'):

The first one with no results and the second one with error


I don't use TurboGears, but is there not a setting or global somewhere that indicates that the tests are running? In large systems, there are often small changes that need to be made when running tests. Switching between SQLite and MySQL is just one example.

Ned Batchelder
Well it has to be somewhere, I thought that ModelTest will be a good flag, but I'm new to python and nosetest.

Presumably if nose is running, the 'nose' top-level module will have been imported. You should be able to test that with

if 'nose' in sys.modules:
    print "Nose is running, or at least has been imported!"
    #or whatever you need to do if nose is running

Of course this is not a foolproof test, which assumes that there's no other reason why nose would be imported.

Vinay Sajip
That did it! just before the variable assignment I put the condition and now my nosetests work again. Thank you