I have the following directory structure
/home/ubuntu/test/
- Foo/
- Foo.py
- __init__.py
- Test/
- conftest.py
- __init__.py
- Foo/
- test_Foo.py
- __init__.py
Foo.py contains
class Foo(object):
def __init__(self):
pass
conftest.py contains:
import pytest
import sys
print sys.path
from Foo.Foo import Foo
@pytest.fixture(scope="session")
def foo():
return Foo()
test_Foo.py contains:
class TestFoo():
def test___init__(self,foo):
assert True
If I run pytest . in the Test folder then I get an error that it can not find the module Foo:
Traceback (most recent call last):
File "/home/ubuntu/pythonVirtualEnv/local/lib/python2.7/site-packages/_pytest/config.py", line 379, in _importconftest
mod = conftestpath.pyimport()
File "/home/ubuntu/pythonVirtualEnv/local/lib/python2.7/site-packages/py/_path/local.py", line 662, in pyimport
__import__(modname)
File "/home/ubuntu/pythonVirtualEnv/local/lib/python2.7/site-packages/_pytest/assertion/rewrite.py", line 212, in load_module
py.builtin.exec_(co, mod.__dict__)
File "/home/ubuntu/pythonVirtualEnv/local/lib/python2.7/site-packages/py/_builtin.py", line 221, in exec_
exec2(obj, globals, locals)
File "<string>", line 7, in exec2
File "/home/ubuntu/test/Test/conftest.py", line 6, in <module>
from Foo.Foo import Foo
ImportError: No module named Foo
ERROR: could not load /home/ubuntu/test/Test/conftest.py
The sys.path that is printed out in conftest.py seems to include the /home/ubuntu/test path so it should be able to find Foo.py, right?
The thing is that it only works when I move conftest.py to the folder below.
I run pytest 3.2.2