gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:44 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com