Pytest running from parent directory?

Viewed 9076

I'm starting to use pytest, and I think I have something set up wrong.

I have directory called "cyan" with all of my code. It has some top-level stuff and a lib directory with all of the code that does work, as is normal.

I have a tests directory where I'm trying to put pytest tests.

I currently have one test: test_A:

import pytest
from cyan.lib import dataCrunch
import os,sys

def test_foo():
    print os.getcwd()
    print sys.path
    assert 1==0

You'll notice the "from cyan.lib import" line. It SHOULD be "from lib import", but that doesn't work.

The reason it doesn't work is clear from the results of the test:

/Users/brianp/work/cyan
['/Users/brianp/work', .........]

the .... is all standard library venv stuff, as expected.

when I print sys.path from a normal python run I get:

['', .........]

which seems right.

So, somehow when I run pytest, sitting in the cyan directory, the parent directory is getting into the pythonpath instead of the current directory.

I have __init__.py in all appropriate directories.

ADDED:

Ok, thanks to @timchap's comment I've learned some things:

The docs that Tim posted imply that having a pytest.ini in my cyan dir should make that be the rootdir. THAT doesn't work.

What appears to be happening is that it starts at the tests dir, and looks up in the path until it finds a directory WITHOUT __init__.py. Since my root directory has one, it kept going up until the parent directory.

Maybe that's the entire problem? that my root dir has __init__.py? Seems like a weird assumption to make...

2 Answers
Related