Re: pyramid.paster.get_app fails with AttrributeError

94 views
Skip to first unread message

Michael Merickel

unread,
Jun 26, 2012, 1:18:59 PM6/26/12
to pylons-...@googlegroups.com
"import pyramid.paster" should fix it. I never use submodules without
importing them directly, mainly because I don't understand how Python
handles it.

On Tue, Jun 26, 2012 at 11:20 AM, Emmanuel Cazenave <man...@gmail.com> wrote:
> Hi everyone,
>
> I'm writing functional tests in a pyramid application.
> Below is the base class I use to write functionals tests.
>
> import pyramid
> import unittest
> from myapp.models import  DBSession
>
> class FunctionalTests(unittest.TestCase):
>
>     def setUp(self):
>         app = pyramid.paster.get_app('test.ini')
>         Base.metadata.create_all(DBSession.get_bind())
>         from webtest import TestApp
>         self.testapp = TestApp(app)
>
>   def tearDown(self):
>         del self.testapp
>         Base.metadata.drop_all(DBSession.get_bind())
>         DBSession.remove()
>
> Everything goes fine when I run my tests using `python setup.py test` (my
> setup.py is a setuptools one)
>
> And everything goes wrong when I run it using the `nosetests` command or
> even the standard unittest discover command: `python -m unittest discover`
> In both cases every functional test produces the following error:
>
> Traceback (most recent call last):
>   File "myapp/tests/__init__.py", line 31, in setUp
>     app = pyramid.paster.get_app('test.ini')
> AttributeError: 'module' object has no attribute 'paster'
>
> I'm quite completely lost on this one. Any idea ?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/6-ljzzzCTpoJ.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

Mike Orr

unread,
Jun 26, 2012, 6:01:06 PM6/26/12
to pylons-...@googlegroups.com
It would be visible in the parent package (pyramid) only if the __init__.py imported it.
--
Mike Orr <slugg...@gmail.com>

Emmanuel Cazenave

unread,
Jun 27, 2012, 4:51:18 AM6/27/12
to pylons-...@googlegroups.com
Thanks guys.

Using this solves the problem:

from pyramid import paster

class FunctionalTests(unittest.TestCase):

    def setUp(self):
        app = paster.get_app('test.ini')


I understand that the paster module is not imported in the pyramid's __init__, so it's not visible.
But why the hell does this work using `python setup.py test`:

import pyramid
import unittest

class FunctionalTests(unittest.TestCase):

    def setUp(self):
        app = pyramid.paster.get_app('test.ini')

And also I have some Integration tests using this base class:

import pyramid

class ViewIntegretionTest(unittest.TestCase):

    def setUp(self):
        self.config = pyramid.testing.setUp()

And this works perfectly well using `python setup.py test` or `nosetests` or `python -m unittest discover`.
As far I understand this should not work at all. The `testing` module is not imported in pyramid's __init__ file (just like the `paster` module).
Below is the pyramid's __init__ file of the pyramid version I'm working with (1.3).

from pyramid.request import Request
from pyramid.response import Response
Response.RequestClass = Request
Request.ResponseClass = Response
del Request, Response


Thanks !
> To post to this group, send email to pylons-discuss@googlegroups.com.

> To unsubscribe from this group, send email to

> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to pylons-discuss+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.




--
Mike Orr <slugg...@gmail.com>

Michael Merickel

unread,
Jun 27, 2012, 8:31:33 AM6/27/12
to pylons-...@googlegroups.com
On Wed, Jun 27, 2012 at 3:51 AM, Emmanuel Cazenave <man...@gmail.com> wrote:
> I understand that the paster module is not imported in the pyramid's
> __init__, so it's not visible.
> But why the hell does this work using `python setup.py test`:

Most likely this works with `setup.py test` because you do not have
the `test_suite` option properly configured and thus the unittest
discovery mechanism is not finding your tests but nosetests does find
them with its more aggressive scanning, thus your tests aren't
actually running via `setup.py test`.

Emmanuel Cazenave

unread,
Jun 27, 2012, 10:24:37 AM6/27/12
to pylons-...@googlegroups.com
I checked but now but no, every tests are running with each test running  method.

But I think I understand.
Python 2.7.2 (default, Oct 20 2011, 18:06:34)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyramid import paster
>>> import pyramid
>>> pyramid.paster
<zope.deprecation.deprecation.DeprecationProxy object at 0x1fa5c10>
>>>

So maybe the test discovery mechanism of setuptools does an import like this which enable the `pyramid.paster.get_app` not to crash in my functionnal test. And maybe nosetests does not....sounds likely ?
Any way if someone could point me to a good explanation of the python import mechanism, because I don't understand why doing this:
>>> from pyramid import paster
before this
>>> import pyramid
lets you access to the `paster` module through the pyramid package:
>>> pyramid.paster
<zope.deprecation.deprecation.DeprecationProxy object at 0x1fa5c10>

As far I understand this:
>>> from pyramid import paster
loads the paster module put it in your local namespace. I don't understand why invoking this command does not crash:
>>> pyramid.paster

Thanks.
Reply all
Reply to author
Forward
0 new messages