AttributeError:'thread._local'对象没有属性'browser'

时间:2021-02-04 18:18:03

I am stuck on an AttributeError using lettuce in python.

我在python中使用莴苣时遇到了一个AttributeError。

I'm trying to follow the lettuce=0.2.19 documentation no the website http://lettuce.it/reference/terrain.html#reference-terrain but cannot figure out what I'm doing wrong.

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

I am using virtualenv to start a clean environment. I want to add a very stupid feature for testing.

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

the organisation of the directory is

目录的组织是

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

Here is my terrain.py file:

这是我的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()

and the user_steps.py file:

和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

When using the following command:

使用以下命令时:

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

I get the following error:

我收到以下错误:

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

1 个解决方案

#1


1  

As much as I know, while launching tests through manage.py harvest, lettuce expects to find terrain.py in the folder where manage.py is. Try to place terrain.py in that folder.

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

#1


1  

As much as I know, while launching tests through manage.py harvest, lettuce expects to find terrain.py in the folder where manage.py is. Try to place terrain.py in that folder.

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