Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module Import Error running py.test with modules on Path

I'm unable to import my module for testing in the way that I'd like. I'm running all of this in a virtualenv on 2.7.2

I have a directory structure like

/api
    /api
        __init__.py
        my_module.py
    /tests
        my_module_test.py

I have my PYTHONPATH set to /Path/api/. I CD into /Path/api and run the following

 py.test tests/my_module_test.py   

It does not work in the following case:

  1. When I have the following at the top of my_module_test.py from api.my_module import my_function

It does work in the following case:

  1. When I have the following at the top of my_module_test.py from my_module import my_function

Why am I not able to import my module as in case 1?

like image 974
bearrito Avatar asked Dec 01 '22 21:12

bearrito


1 Answers

I use PYTHONPATH as

PYTHONPATH=`pwd` py.test tests/my_module_test.py
like image 109
Christophe Chauvet Avatar answered Dec 03 '22 10:12

Christophe Chauvet