I'm following the flaskr tutorial here, and I'm struggling with running tests.
➜ pytest
ImportError while loading conftest 'flaskr_app/tests/conftest.py'.
tests/conftest.py:5: in <module>
from ..flaskr import create_app
E ImportError: attempted relative import with no known parent package
Pytest seems to be complaining about relative imports. Here is how I set up the import in conftest.py
:
import os
import tempfile
import pytest
from ..flaskr import create_app
from ..flaskr import get_db, init_db
Here's how my project directory looks like.
➜ tree
.
├── flaskr
│ ├── MANIFEST.in
│ ├── __init__.py
│ ├── auth.py
│ ├── blog.py
│ ├── db.py
│ ├── schema.sql
│ ├── static
│ │ └── style.css
│ └── templates
│ ├── auth
│ │ ├── login.html
│ │ └── register.html
│ ├── base.html
│ └── blog
│ ├── create.html
│ ├── index.html
│ └── update.html
├── instance
│ └── flaskr.sqlite
├── setup.cfg
├── setup.py
└── tests
├── conftest.py
└── data.sql
Since the flaskr
directory resides in the parent directory of tests
directory, I thought it would be appropriate to import the package from ..flaskr
.
Can anyone tell me what's causing this error?