aloetesting/aloe

TestStep.testcase does not find AloeTestCase

Closed this issue · 6 comments

I am using aloe (0.0.30) from aloe-django (0.0.15), however I am hitting these 2 errors which seem have the same root cause from here which is that the feature object does not have a testclass attribute.

Below are the 2 stack traces and my feature file, any help would be greatly appreciated, I may well be missing something obvious!

Feature: Feature 1
    As a XXXXX I want to do YYYYY

    # Background:
    #     Given I am logged in as "ceo@growing_company.com"

    Scenario: Successful Update
        When I am logged in as "ceo@growing_company.com"
        And I access the url "/dashboard/settings"
        ...

The tracebacks:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/aloe/registry.py", line 163, in wrapped
    return function(*args, **kwargs)
  File "/vagrant/founders/users/features/duedil.feature", line 9, in Successful Update
    When I am logged in as "ceo@growing_company.com"
  File "/usr/local/lib/python2.7/dist-packages/aloe/registry.py", line 163, in wrapped
    return function(*args, **kwargs)
  File "/vagrant/founders/terrain.py", line 306, in given_i_am_logged_in_as
    step.given('I have signed up as "{}" with password "{}"'.format(email, password))
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 72, in given
    self.behave_as(self.step_keyword('given') + string)
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 68, in behave_as
    self.testclass.behave_as(self, string)
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 58, in testclass
    return self.background.feature.testclass
AttributeError: 'TestStep' object has no attribute 'background'

this is where the background section is uncommented revealing the actual error

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/aloe/registry.py", line 163, in wrapped
    return function(*args, **kwargs)
  File "/vagrant/founders/users/features/duedil.feature", line 2, in Successful Update
    As a business leader I want to update the company I work at so that my profile accurately reflects my current job
  File "/vagrant/founders/users/features/duedil.feature", line 2, in background
    As a business leader I want to update the company I work at so that my profile accurately reflects my current job
  File "/usr/local/lib/python2.7/dist-packages/aloe/registry.py", line 163, in wrapped
    return function(*args, **kwargs)
  File "/vagrant/founders/terrain.py", line 306, in given_i_am_logged_in_as
    step.given('I have signed up as "{}" with password "{}"'.format(email, password))
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 72, in given
    self.behave_as(self.step_keyword('given') + string)
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 68, in behave_as
    self.testclass.behave_as(self, string)
  File "/usr/local/lib/python2.7/dist-packages/aloe/testclass.py", line 58, in testclass
    return self.background.feature.testclass
AttributeError: 'TestFeature' object has no attribute 'testclass'

I have some ideas about why would this happen, but can I see the given_i_am_logged_in_as function for completeness?

Also, did you customize TestCase by any chance?

Hi, I have not customised TestCase in anyway and here is the function:

@step(u'I am logged in as "([^"]*)"')
def i_am_logged_in_as(step, email):
    password = '123456'
    auth_login = reverse("registration:login")
    step.given('I have signed up as "{}" with password "{}"'.format(email, password))
    step.when('I access the url "{}"'.format(django_url(auth_login)))
    step.then('I hit the template "registration/login.html"')
    step.then('Fill the field "signin-email" with "{}"'.format(email))
    step.then('Fill the field "signin-password" with "{}"'.format(password))

basically I will just be calling a lot of other steps

I have found a bug in using behave_as on background steps, check out the branch from #68. However, I'm not sure if your problem is the same; if you still run into it with that branch, maybe prepare a minimal test case with your definitions?

Hi

That seems to have fixed it! Thank you for the very swift response & fix it is very much appreciated 😃, my test is now failing but that is definitely down to my code not the library as far as I can tell at this point.

Thanks for the report! Released as .31.