【问题标题】:AttributeError: 'thread._local' object has no attribute 'browser'AttributeError:“thread._local”对象没有属性“浏览器”
【发布时间】:2013-09-05 14:16:30
【问题描述】:

我在 python 中使用生菜时遇到了 AttributeError。

我正在尝试关注 lettuce=0.2.19 文档而不是网站 http://lettuce.it/reference/terrain.html#reference-terrain,但无法弄清楚我做错了什么。

我正在使用 virtualenv 来启动一个干净的环境。 我想添加一个非常愚蠢的测试功能。

目录的组织是

features
    |_terrain.py
    |_ user_reauth.feature
    |_ user_steps.py

这是我的 terrain.py 文件:

from lettuce import before, after, world
from lettuce.django import django_url
from selenium import selenium

@before.harvest
def prepare_browser_driver(variables):
    if variables.get('run_server', False) is True:
        world.browser = selenium('localhost', 4444, '*firefox', django_url('/'))
        world.browser.start()

@after.harvest
def shutdown_browser_driver(results):
    world.browser.stop()

还有 user_steps.py 文件:

from lettuce import world, step
from lettuce.django import django_url

@step(u'User is already authenticated with username "(.*)')
def user_is(step, username):
    assert 1==1

@step(u'I go to the "(.*)" URL')
def i_go_to_the_url(step, url):
    world.response = world.browser.visit(django_url(url))

@step(u'I should see "(.*)"')
def i_should_see(step, text):
    assert text in world.browser.html

使用以下命令时:

python manage.py harvest --settings=my_settings dir/features/user_reauth.feature

我收到以下错误:

line 13, in shutdown_browser_driver
    world.browser.stop()
AttributeError: 'thread._local' object has no attribute 'browser'

【问题讨论】:

    标签: python django lettuce splinter


    【解决方案1】:

    据我所知,在通过manage.py harvest 启动测试时,lettuce 期望在 manage.py 所在的文件夹中找到 terrain.py。 尝试将terrain.py 放在该文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2012-12-01
      • 2021-04-19
      相关资源
      最近更新 更多