W liście Bryan z dnia środa 18 listopada 2009: > I wrote a simple unit test for a class to test that the constructor > was handling keyword arguments correctly: > obj = Test(a='foo'') > assert obj.a == 'foo > > The test passes fine when run alone, but when run with all the other > test in my pylons app, sqlalchemy complains because Test.a is actually > a relation to another mapped object, so when I try to assign a string > to it, it complains that "str object has no attribute > '_sa_instance_state". This happens because when the entire test > package in my pylons app runs, the sqlalchemy mapping also runs, which > changes the behavior of the class. > > I don't want the unit tests for my class Test to have to know about > what kind of object will be stored in Test.a in the actual app. >
You can set up mappers in setUp function in test suites that need them, and remove them in tearDown (sqlalchemy has remove_mappers or some similarily named function). Personally, I don't have mappers setup as top-level functions in any module, but have a specific function just to define mappers, which I run during application setup. -- Paweł Stradomski -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=.
