I have a question related to sqlalchemy and testing, not sure if this is the best place to ask so let me know if I am asking here in error.

I am trying to learn to write and run tests using py.test. Currently I am working on a spreadsheet scrapper that gathers data from a directory tree of spreadsheets and puts them into an sqlite database to be manipulated from there. In any function that has a session.query object however I get a "global name 'session' not defined" error when I run the tests. Here is an example of the code:

def get_list_of_filesprocessed():
'''Look in filesprocessed table and return list of all the values in the filename field''
    return [r.filename for r in session.query(FilesProcessed).all()]

if __name__ == '__main__':
    engine = create_engine('sqlite:///scrapper.db', echo=True)
    Base = declarative_base()
    Session = sessionmaker(bind=engine)
    session = Session()

How can I make the session available to the tests when they are run? I have tried creating a decorator in the test file to initialize the session to no avail. Any hints are appreciated.

thomas

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to