Skip to content


Subversion checkout URL

You can clone with
Download ZIP


attempted relative import in non-package python #431

richardzulu opened this Issue · 7 comments

5 participants


Whenever I run python harvest, I receive a traceback call as depicted

Traceback (most recent call last):
File   "/home/xxxx/programming/apps/xxxxx/sipi/src/lettuce/lettuce/django/management/commands/", line 185, in handle
result =
File "/home/xxxxx/programming/apps/xxxx/sipi/src/lettuce/lettuce/", line 148, in run
File "/home/xxxxx/programming/apps/xxxxxx/sipi/src/lettuce/lettuce/", line 58, in   find_and_load_step_definitions
raise e
ValueError: Attempted relative import in non-package when importing  /home/xxxx/programming/apps/xxxx/sipi/local/lib/python2.7/site- packages/debug_toolbar/

i too am having this issue -- is anyone aware of a fix or workaround?


I just remove debug_toolbar from settings when harvesting:

if 'harvest' in sys.argv or 'test' in sys.argv:

I've just faced this issue. Nothing to do with debugtoolbar, though...


The issue here is:

  • some of my project's apps have no "features" module
  • still, i'm reusing a variable "PROJECT_APPS" (used for django_jenkin) for LETTUCE_APPS
  • but their have some relative imports (which is fair)
  • lettuce can't skip without throwing this error (it ends execution)


  • Adding "features" directory and it's at each of the LETTUCE_APPS without features
  • or maintaining a curated list of apps with only those who actually have features (DRY violation)

Maybe a good solution would be catching this exception and skipping the loading...


Another workaround:

for app in PROJECT_APPS:


Okay, this is a bug in the feature loader when combined with relative imports, i.e. one step file importing things from another step file using relative imports.


There's a fix for this on

Although it requires your steps directory to be importable as part of your Python package to work (i.e. you need files. Alternatively consider Aloe, which is next generation Lettuce based on nose (and takes a whole bunch of the code from new-parser).

@danni danni referenced this issue from a commit in infoxchange/aloe
@danni danni Adapt test to demonstrate broken relative imports
From gabrielfalcao/lettuce#431 -- Lettuce's
step loader, on which Aloe is based, cannot handle relative imports.

The problem appears to be caused by adding the directory itself to the
package import root (this would make it an absolute import). It would be
better not to manipulate the import path and instead determine the
Python package path for the file we wish to import from a path we
already have.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.