I have all my mappers setup in a single function that gets called in
my pylons environment.py file during app startup.  But the default
setup for pylons testing is that the base test controller sets up a
paste.fixture.TestApp so we can make HTTP calls to the app to test our
controllers.  During this setup, my mapping function is called, which
works out for most cases, but it prevents me from assigning the wrong
type to object attributes that are mapped to another Class.

To avoid this I would need to pull my simple unit tests out of the
default pylons tests directory, but I was hoping I could avoid this.
Maybe I will move the paste.fixture.TestApp creation down into the
test package hierarchy one level so I could have simple tests at the
first level of the tests package, then any tests that require the app
to be running to be under another subpackage in the test package.

On Nov 18, 2:11 pm, Paweł Stradomski <[email protected]> wrote:
> 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=.


Reply via email to