Hi.
I took a look at the code and it doesn't appear to be a nose problem.
It's either a bug in Routes or somehow the Routes config is not
getting configured properly during your test run. I can't see
anything in environment.py or tests/__init__.py that would indicate
your pylons app is out of the ordinary. The subdomain code triggers a
different function which is why you only see the error when turning on
subdomains. However, you can see that it is a configuration problem
(or a bug) by doing this directly in your test:
class TestLibraryController(TestController):
def test_get_leafs(self):
from routes import request_config
config = request_config()
config.environ
For me, that triggers the error directly:
Traceback (most recent call last):
File
"/Users/kumar/Downloads/helloworld/helloworld/tests/functional/test_library.py",
line 10, in test_get_leafs
config.environ
File
"/Users/kumar/Downloads/helloworld/env/lib/python2.5/site-packages/Routes-1.7.1-py2.5.egg/routes/__init__.py",
line 14, in __getattr__
return getattr(self.__shared_state, name)
AttributeError: 'thread._local' object has no attribute 'environ'
I'd suggest filing a bug with Routes after double checking that your
app is configuring the Routes config as it should.
K
On Thu, May 15, 2008 at 3:19 AM, Pavel Skvazh <[EMAIL PROTECTED]> wrote:
>
> Thanks for your reply!
>
> I've tried the method you described and it doesn't seem to work
> unfortunatly.
> Just stressing it out.
> The second i remove
> map.sub_domains = True
> and conditions=dict(sub_domain=['my']) from routing.py everything
> starts working.
>
> And the failure
> looks like
>
> Traceback (most recent call last):
> File "D:\Pylons\rusbiz\trunk\rusbiz\tests\functional
> \test_catalog.py", line 10, in setUp
> self.login('storos', 'explore')
> File "D:\Pylons\rusbiz\trunk\rusbiz\tests\functional
> \test_catalog.py", line 16, in login
> return url_for(controller='users', action='login')
> File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
> \util.py", line 205, in url_for
> newargs = _screenargs(kargs)
> File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
> \util.py", line 55, in _screenargs
> memory_kargs = _subdomain_check(config, memory_kargs)
> File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
> \util.py", line 66, in _subdomain_check
> fullhost = config.environ.get('HTTP_HOST') or \
> File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
> \__init__.py", line 14, in __getattr__
> return getattr(self.__shared_state, name)
> AttributeError: 'thread._local' object has no attribute 'environ'
>
> it occurs when i try to call url_for(controller='users',
> action='login', sub_domain='my')
>
> I can send you the sample project that displays this error
>
> On May 13, 9:26 pm, "Kumar McMillan" <[EMAIL PROTECTED]> wrote:
>> It's hard to understand what might be going on here but my only guess
>> is that your app-setup code to populate the thread local config object
>> is not getting run at the right time. This is tricky to get right in
>> nose because often times parts of your app want to access config
>> *before* it can be imported. What nose does is import just about
>> everything in your package before it runs the tests. If your test
>> setup is done like the pylons docs suggest, that is, at the module
>> level of test/__init__.py -- not within setup() -- then try this and
>> see if it helps:
>>
>> nosetests --where=yourapp/tests
>>
>> that will change dir to "yourapp/tests" (adjust the path as necessary)
>> and will only import from the tests directory. However you will have
>> to ensure that each test module says from yourapp import tests at the
>> top so the setup code gets run. Double check that.
>>
>> If that still doesn't work you'd have to revert back to a version of
>> your app where tests run OK then compare the differences. You might
>> want to run nosetests --debug=nose.importer,nose.selector to help
>> compare the differences in test execution.
>>
>> On Wed, May 7, 2008 at 8:49 AM, Pavel Skvazh <[EMAIL PROTECTED]> wrote:
>>
>> > Has anyone experienced problems with running nosetests on contoller,
>> > that is routed to the sub-domain?
>>
>> > Here's what I've got
>>
>> > controller/test.py
>> > class TestController(BaseController):
>> > def get(self):
>> > return True
>>
>> > routing.py
>> > Out of the box
>> > map.connect(':controller/:action/:id')
>> > map.connect(':action/:id', controller='main')
>> > map.connect('*url', controller='template', action='view')
>>
>> > class TestController(TestController):
>> > def test_get(self):
>> > response = self.app.get(url_for(controller='test',
>> > action='get'))
>> > r = response.body
>> > assert_true(r)
>>
>> > This works just fine.
>> > What do i change
>> > map.connect(':controller/:action/:id',
>> > conditions=dict(sub_domain=['my']))
>> > map.connect(':action/:id', controller='main',
>> > conditions=dict(sub_domain=['my']))
>> > map.connect('*url', controller='template', action='view')
>>
>> > I change in routing
>> > map.sub_domains = True
>> > map.sub_domains_ignore = ['www']
>>
>> > map.connect(':controller/:action/:id',
>> > conditions=dict(sub_domain=['my']))
>> > map.connect(':action/:id', controller='main',
>> > conditions=dict(sub_domain=['my']))
>> > map.connect('*url', controller='template', action='view')
>>
>> > And then no matter what i do in test
>>
>> > class TestController(TestController):
>> > def test_get(self):
>> > response = self.app.get(url_for(controller='test',
>> > action='get', sub_domain='my'))
>>
>> > r = response.body
>> > assert_true(r)
>>
>> > Here's what i get
>> > Traceback (most recent call last):
>> > File "\tests\functional\test.py", line 10
>> > , in setUp
>> > self.login('storos', 'explore')
>> > File "\tests\functional\test.py", line 16
>> > , in login
>> > response = self.app.post(url_for(controller='test', action='get',
>> > sub_dom
>> > ain='my'),
>> > File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
>> > \util.py", line
>> > 205, in url_for
>> > newargs = _screenargs(kargs)
>> > File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
>> > \util.py", line
>> > 55, in _screenargs
>> > memory_kargs = _subdomain_check(config, memory_kargs)
>> > File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
>> > \util.py", line
>> > 66, in _subdomain_check
>> > fullhost = config.environ.get('HTTP_HOST') or \
>> > File "D:\Python25\lib\site-packages\routes-1.8-py2.5.egg\routes
>> > \__init__.py",
>> > line 14, in __getattr__
>> > return getattr(self.__shared_state, name)
>> > AttributeError: 'thread._local' object has no attribute 'environ'
>>
>> > I cann't really figure what's going on here.
>> > return h.url_for(controller='tests', action='get', sub_domain='my')
>> > returns a perfectly legal url, so i cann't really see why test cann't
>> > see it as well
> >
>
--~--~---------~--~----~------------~-------~--~----~
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]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---