0

I have started to study flask using vscode text editor. So, I created some code that can be seen below:

Folders

enter image description here

app.py

from flask import Flask

def create_app():
    app = Flask(__name__)
    return app

conftest.py

from delivery.app import create_app


@pytest.fixture(scope="module")
def app():
    """Instance of Main Flask app"""
    return create_app()

test_app.py

def test_app_is_created(app):
    assert app.name == "delivery.app"

Ok, it is a simple example. So, when I try to run on terminal

pytest tests --fixtures

an error is returned:

ImportError while loading conftest 'D:\Projetos Dev\delivery\tests\conftest.py'.
tests\conftest.py:2: in <module>
    from delivery.app import create_app
E   ModuleNotFoundError: No module named 'delivery'

I don't understand why this error happens because I am trying to import a module that exists. Someone may help me to understand it?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Try adding an empty `__init__.py` file in your `tests` directory – abc Aug 04 '21 at 17:46
  • @mkrieger1 thank you for your answer! I understood some approaches. –  Aug 04 '21 at 17:50
  • @abc, thank you for your comment. Yes, when I create a `__init__.py` on tests directory the problem was solved! –  Aug 04 '21 at 17:51

0 Answers0