This framework provides a class that formalizes setup/teardown/reloading a test database.
The test class provided is named DBIntegTestCase
. All integ tests should subclass
this class.
- fixture - a file of sql statements, should contain the data necessary to run a specific test configurable on a class level to be ran before every test, or on a per test level.
- destroy_db_script - a file of sql statemens that is ran on test class initialization to teardown the database
- create_db_script - file of sql statements that is ran on test class initialization to prepare the database for testing
- database - a database to run tests against. Right now only mysql is suported
- reset_dbs - for mysql all tables in these dbs will be truncated before each test
The flow of the test framework is:
-
Test class Initialization (is ran for each test class)
- all
DESTROY_DB_SCRIPTS
are executed - all
CREATE_DB_SCRIPTS
are executed
- all
-
Individual Test case initialization (ran before each individual test)
- all class
FIXTURE_FILES
are executed - all individual test fixtures are executed
- all class
To run tests a settings file must be defined. Settings contains credentials
for accessing the database, path information for fixtures, and optional scripts
to be ran before every test. For an example see mysql/settings_test.py
.
FIXTURES_DIR
- fixtures will be looked for in this path, this should keep fixture declarations to just the filename.RESET_DBS
- all dbs in this list will have their tables truncated before each test (for mysql)CREATE_DB_SCRIPTS
- a list of sql files to be executed before each testDESTROY_DB_SCRIPS
- a list of sql files to be exectued before each test. This is the same asCREATE_DB_SCRIPTS
except these are executed first. These separate directives were provided just for ease of use.DATABASE
- contains all database connection informationFIXTURE_FILES
This isDBIntegTesCase
class attribute which is a list of files to execute before each test case.
Example of tests can be foundDB_TEST_SETTINGS=tests.mysql.settings_test python -m unittest discover in test_mysql_test_case.py
. The mysql tests use the
framework to run the tests :)
Running tests require DB_TEST_SETTINGS
envvar to be set.
To run the projects unittests:
- start local mysql server (make sure there is a root/root user with all permissions)
pip install -r requirements.txt
python setup.py develop
DB_TEST_SETTINGS=tests.mysql.settings_test python -m unittest discover
The framework provides a @load_fixture
decorator, which allows an individual
test to specify a single fixture to load in addition to FIXTURE_FILES