AttributeError: 'thread._local' object has no attribute 'browser'

2.7k views Asked by At

I am stuck on an AttributeError using lettuce in python.

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.

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

the organisation of the directory is

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

Here is my terrain.py file:

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:

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

There are 1 answers

0
PukeCloud On

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.