python - 属性错误: 'thread._local' object has no attribute 'browser'

标签 python django lettuce splinter

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

我正在尝试遵循网站 http://lettuce.it/reference/terrain.html#reference-terrain 上的 lettuce=0.2.19 文档但无法弄清楚我做错了什么。

我正在使用 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'

最佳答案

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

关于python - 属性错误: 'thread._local' object has no attribute 'browser' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18638765/

相关文章:

python - 如何让 cx_Oracle 在 64 位 Itanium Windows 上运行?

Django : How to pass context?

redis - 在 Redis 的单个命令中使用带 TTL 的 RPUSH

django - 在 View 之外访问经过身份验证的用户

python - 设置 Eclipse 以使用 Lettuce

java - Lettuce RedisCache 抛出 java.util.concurrent.RejectedExecutionException 线程限制超出替换阻塞的工作线程

python - 使用 Twisted 的原始 UDP 数据包

python - 如何将 Python 的 itertools.product 库从列表理解转换为普通的 for 循环?

python - 美丽汤 : Fetched all the links on a webpage how to navigate through them without selenium?

python - 为什么 Django 的信号处理默认使用弱引用进行回调?