Skip to content

Commit

Permalink
Merge branch 'master' into sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
juliotrigo committed Jan 6, 2017
2 parents 72d9e4a + 21c6cc9 commit eb21f5a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ There are some Makefile targets that can be used to run the tests. A
test database will be created, used during the tests and destroyed
afterwards.

The default configuration uses SQLite with the following test URI:
The default configuration uses both SQLite and MySQL (if the driver is
installed) to run the tests, with the following URIs:

.. code-block:: shell
sqlite+pysqlite:///test_sqlalchemy_filters.db
mysql+mysqlconnector://root:@localhost:3306/test_sqlalchemy_filters
Example of usage:

Expand All @@ -160,8 +162,11 @@ Example of usage:
$ make coverage
$ # overriding DB parameters
$ ARGS='--test-db-uri mysql+mysqlconnector://root:@192.168.99.100:3340/test_sqlalchemy_filters' make test
$ ARGS='--test-db-uri mysql+mysqlconnector://root:@192.168.99.100:3340/test_sqlalchemy_filters' make coverage
$ ARGS='--mysql-test-db-uri mysql+mysqlconnector://root:@192.168.99.100:3340/test_sqlalchemy_filters' make test
$ ARGS='--sqlite-test-db-uri sqlite+pysqlite:///test_sqlalchemy_filters.db' make test
$ ARGS='--mysql-test-db-uri mysql+mysqlconnector://root:@192.168.99.100:3340/test_sqlalchemy_filters' make coverage
$ ARGS='--sqlite-test-db-uri sqlite+pysqlite:///test_sqlalchemy_filters.db' make coverage
License
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
'dev': [
'pytest==3.0.5',
'flake8==3.2.1',
'coverage==4.2.0',
'mysql-connector-python==2.1.5',
'coverage==4.3.1',
'sqlalchemy-utils==0.32.12',
],
'mysql': [
'mysql-connector-python==2.1.5',
]
},
dependency_links=[
Expand Down
52 changes: 43 additions & 9 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,33 @@
from test.models import Base


SQLITE_TEST_DB_URI = 'SQLITE_TEST_DB_URI'
MYSQL_TEST_DB_URI = 'MYSQL_TEST_DB_URI'


def pytest_addoption(parser):
parser.addoption(
'--test-db-uri',
'--sqlite-test-db-uri',
action='store',
dest='TEST_DB_URI',
dest=SQLITE_TEST_DB_URI,
default='sqlite+pysqlite:///test_sqlalchemy_filters.db',
help=(
'DB uri for testing (e.g. '
'"mysql+mysqlconnector:username:password@localhost:3306'
'"sqlite+pysqlite:///test_sqlalchemy_filters.db")'
)
)

parser.addoption(
'--mysql-test-db-uri',
action='store',
dest=MYSQL_TEST_DB_URI,
default=(
'mysql+mysqlconnector://root:@localhost:3306'
'/test_sqlalchemy_filters'
),
help=(
'DB uri for testing (e.g. '
'"mysql+mysqlconnector://username:password@localhost:3306'
'/test_sqlalchemy_filters")'
)
)
Expand All @@ -25,16 +43,32 @@ def pytest_addoption(parser):
@pytest.fixture(scope='session')
def config(request):
return {
'TEST_DB_URI': request.config.getoption('TEST_DB_URI')
SQLITE_TEST_DB_URI: request.config.getoption(SQLITE_TEST_DB_URI),
MYSQL_TEST_DB_URI: request.config.getoption(MYSQL_TEST_DB_URI),
}


@pytest.fixture(scope='session')
def db_uri(config):
return config['TEST_DB_URI']
def test_db_keys():
"""Decide what DB backends to use to run the tests."""
test_db_uris = []
test_db_uris.append(SQLITE_TEST_DB_URI)

try:
import mysql # noqa: F401
except ImportError:
pass
else:
test_db_uris.append(MYSQL_TEST_DB_URI)

return test_db_uris


@pytest.yield_fixture(scope='session')
@pytest.fixture(scope='session', params=test_db_keys())
def db_uri(request, config):
return config[request.param]


@pytest.fixture(scope='session')
def connection(db_uri):
create_db(db_uri)
engine = create_engine(db_uri)
Expand All @@ -48,7 +82,7 @@ def connection(db_uri):
destroy_database(db_uri)


@pytest.yield_fixture()
@pytest.fixture()
def session(connection):
Session = sessionmaker(bind=connection)
db_session = Session()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ skipdist=True
whitelist_externals = make

commands =
pip install -U --editable .[dev] --process-dependency-links
pip install -U --editable ".[dev, mysql]" --process-dependency-links
make coverage ARGS='-x -vv'

0 comments on commit eb21f5a

Please sign in to comment.