lettuce
lettuce copied to clipboard
attempted relative import in non-package python
Whenever I run python manage.py 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/harvest.py", line 185, in handle
result = runner.run()
File "/home/xxxxx/programming/apps/xxxx/sipi/src/lettuce/lettuce/__init__.py", line 148, in run
self.loader.find_and_load_step_definitions()
File "/home/xxxxx/programming/apps/xxxxxx/sipi/src/lettuce/lettuce/fs.py", 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/utils.py
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:
INSTALLED_APPS.remove('debug_toolbar')
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 tests.py have some relative imports (which is fair)
- lettuce can't skip without throwing this error (it ends execution)
Workarounds:
- Adding "features" directory and it's init.py 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:
LETTUCE_APPS = []
for app in PROJECT_APPS:
try:
__import__(app+'.features')
LETTUCE_APPS.append(app)
except:
pass
LETTUCE_APPS = tuple(LETTUCE_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 https://github.com/infoxchange/lettuce/tree/new-parser
Although it requires your steps directory to be importable as part of your Python package to work (i.e. you need __init__.py
files. Alternatively consider Aloe, which is next generation Lettuce based on nose (and takes a whole bunch of the code from new-parser
).