lettuce icon indicating copy to clipboard operation
lettuce copied to clipboard

attempted relative import in non-package python

Open richardzulu opened this issue 11 years ago • 7 comments

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

richardzulu avatar Feb 23 '14 19:02 richardzulu

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

ersherr avatar Apr 23 '14 16:04 ersherr

I just remove debug_toolbar from settings when harvesting:

if 'harvest' in sys.argv or 'test' in sys.argv:
    INSTALLED_APPS.remove('debug_toolbar')

michelts avatar Apr 23 '14 16:04 michelts

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

dhiana avatar Jul 14 '14 20:07 dhiana

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...

dhiana avatar Jul 14 '14 21:07 dhiana

Another workaround:

LETTUCE_APPS = []
for app in PROJECT_APPS:
    try:
        __import__(app+'.features')
        LETTUCE_APPS.append(app)
    except:
        pass

LETTUCE_APPS = tuple(LETTUCE_APPS)

dhiana avatar Jul 14 '14 22:07 dhiana

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.

danni avatar Jul 23 '15 07:07 danni

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).

danni avatar Jul 23 '15 07:07 danni