Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Import error in hooks #17

Closed
teone opened this issue Apr 7, 2016 · 10 comments
Closed

Import error in hooks #17

teone opened this issue Apr 7, 2016 · 10 comments

Comments

@teone
Copy link

teone commented Apr 7, 2016

I'm trying to create a helpers module to setup the db in my tests and import in into my hooks.py file.

This is the folder structure:

helpers
- __init__.py
- subscribers.py
hooks.py

the subscriber module is:

import os
import sys
sys.path.append("/opt/xos")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
import django
from core.models import *
#from hpc.models import *
from services.cord.models import *
django.setup()

def createTestSubscriber():
    # deleting all subscribers
    for s in CordSubscriberRoot.objects.all():
        print(s.name)
        s.delete(purge=True)

    # creating the test subscriber
    subscriber = CordSubscriberRoot(name='Test Subscriber 1')
    subscriber.save()
    print "Subscriber Created"

I was trying to import it into hooks.py as:
from helpers import subscriber

but I keep getting: ImportError: No module named helpers,
googling around it seems to be the right syntax, any idea of what I’m missing?

Thanks in advance

@w-vi
Copy link
Contributor

w-vi commented Apr 7, 2016

@teone thanks for the report, what version of python are you using?

@teone
Copy link
Author

teone commented Apr 7, 2016

Python 2.7.6

@w-vi
Copy link
Contributor

w-vi commented Sep 18, 2016

Sorry for not repsonding got busy by other tasks. Is it still valid or have you found a solution?

@DomhnallBoyle
Copy link

I'm having the same problem trying to import a function from another module into the dredd hooks module. It keeps saying 'No module named ...' even though the module is in the same directory as the dredd hooks one

@w-vi
Copy link
Contributor

w-vi commented Oct 24, 2016

@DomhnallBoyle Are you on Python 2.7 as well?

@DomhnallBoyle
Copy link

Yes 2.7.6

@w-vi
Copy link
Contributor

w-vi commented Oct 24, 2016

Cheers, will look into it.

@DomhnallBoyle
Copy link

Thank-you

w-vi pushed a commit that referenced this issue Oct 24, 2016
w-vi pushed a commit that referenced this issue Oct 24, 2016
@honzajavorek
Copy link
Contributor

@teone @DomhnallBoyle could you please confirm this has been fixed in #24? Thanks!

@DomhnallBoyle
Copy link

Yes works great, thank-you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants