SunPowered SunPowered - 23 days ago 12
Python Question

Neo4j ImpermanentDatabase in python unittests

I am trying to create unit tests for a python project that will interface with a Neo4j Graph database.

Currently, I am implementing the embedded graph database, but will likely migrate to a REST interface if I choose to deploy this to a web application.
I have intstalled v1.9rc2 of the embedded neo4j project, installed via

pip
on a virtual environment.

There are mentionings of a java class
org.neo4j.test.TestGraphDatabaseFactory
, here, which sounds perfect for what I have in mind. I am currently reading and writing to a database on file, which is ok, but I am having trouble properly cleaning up after ech test that doesn't include a call to
shutil.rmtree
... or is that how it should be done?

Another possible method is to create and shutdown the database for each test, via the
setUp
and
tearDown
methods of my
TestCase
.

>>> import neo4j
>>> print neo4j.__version__
'1.9.c2'

Answer

The best practice is to create and shutdown the database individually for each test using setUp/tearDown - exactly as you've mentioned.

side note: 1.9rc2 is rather outdated, consider upgrading to latest stable since couple of bugs have been fixed since then.

Comments