Building neo4j app with Python - Problem with pytest: Error loading create_app from api + solution

martin3
Node Clone

In chapter "Adding the driver" you are supposed to runt the first pytest, to test the functionality of the code.

There is an error when running command:

pytest tests/01_connect_to_neo4j__test.py

..as described in the exercise. At least on my laptop running Mac OS X, Python 3.8.9. I get the following error:

ImportError while loading conftest './tests/conftest.py'.
tests/conftest.py:7: in <module>
    from api import create_app
E   ModuleNotFoundError: No module named 'api'

The reason for the error, and the solution to it, is explained here:

The solution to the problem is to run pytest from the following command:

python -m pytest tests/01_connect_to_neo4j__test.py

Because this will make sure that class create_app from api/init.py is loaded when importing conftest.py.

1 ACCEPTED SOLUTION

adam_cowley
Neo4j
Neo4j

Thanks for the heads up, I've merged a PR on the repo that adds an __init__.py to the tests folder. Hopefully, no one else will run into this issue.

View solution in original post

1 REPLY 1

adam_cowley
Neo4j
Neo4j

Thanks for the heads up, I've merged a PR on the repo that adds an __init__.py to the tests folder. Hopefully, no one else will run into this issue.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit - November 16 - 17, 2022.


Free NODES Training Series


October 19th -

Intro to Neo4j


October 20th -

Healthcare Analytics Using Neo4j


October 25th -

Handling Neo4j data with Apache Hop


October 26th -

Blazing Fast Graphs: Hands-on with Apache Arrow and Neo4j


November 2nd -

Graph EDA Using the Neo4j GDS Client