diff --git a/Makefile b/Makefile index 414fe6d..90a3fdb 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ test: flake8 pylint pytest flake8: - flake8 nameko_sqlalchemy.py test + flake8 nameko_sqlalchemy test pylint: pylint nameko_sqlalchemy -E pytest: - coverage run --concurrency=eventlet --source nameko_sqlalchemy.py --branch -m pytest test + coverage run --concurrency=eventlet --source nameko_sqlalchemy --branch -m pytest test coverage report --show-missing --fail-under=100 diff --git a/nameko_sqlalchemy/__init__.py b/nameko_sqlalchemy/__init__.py new file mode 100644 index 0000000..61e7828 --- /dev/null +++ b/nameko_sqlalchemy/__init__.py @@ -0,0 +1,3 @@ +from nameko_sqlalchemy.database_session import ( # noqa: F401 + DatabaseSession, DB_URIS_KEY, Session +) diff --git a/nameko_sqlalchemy.py b/nameko_sqlalchemy/database_session.py similarity index 100% rename from nameko_sqlalchemy.py rename to nameko_sqlalchemy/database_session.py diff --git a/pytest_fixtures.py b/nameko_sqlalchemy/pytest_fixtures.py similarity index 88% rename from pytest_fixtures.py rename to nameko_sqlalchemy/pytest_fixtures.py index d6ac5a3..23d16f2 100644 --- a/pytest_fixtures.py +++ b/nameko_sqlalchemy/pytest_fixtures.py @@ -1,7 +1,6 @@ import pytest from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker @@ -38,13 +37,10 @@ def db_url(request): @pytest.fixture(scope='session') def model_base(): - """ Returns `sqlalchemy.ext.declarative.declarative_base` used - for declarative database definitions + """Override this fixture to return declarative base of your model http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html - You need to override this fixture to return declarative base of your model: - .. code-block:: python from sqlalchemy.ext.declarative import declarative_base @@ -63,7 +59,7 @@ class User(DeclarativeBase): def model_base(): return DeclarativeBase """ - return declarative_base() + raise NotImplementedError("Fixture `model_base` has to be overwritten") @pytest.yield_fixture(scope='session') diff --git a/setup.py b/setup.py index 1ab08c4..d616eca 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ author='onefinestay', author_email='engineering@onefinestay.com', url='http://github.com/onefinestay/nameko-sqlalchemy', - py_modules=['nameko_sqlalchemy'], + packages=['nameko_sqlalchemy'], install_requires=[ "nameko>=2.0.0", "sqlalchemy" @@ -23,7 +23,7 @@ }, entry_points={ 'pytest11': [ - 'pytest_fixtures=pytest_fixtures' + 'nameko_sqlalchemy=nameko_sqlalchemy.pytest_fixtures' ] }, zip_safe=True, diff --git a/test/test_pytest_fixtures.py b/test/test_pytest_fixtures.py index 5af2e53..3bc47ce 100644 --- a/test/test_pytest_fixtures.py +++ b/test/test_pytest_fixtures.py @@ -3,6 +3,8 @@ from sqlalchemy import Column, Integer, String from sqlalchemy.ext.declarative import declarative_base +pytest_plugins = "pytester" + class Base(object): pass @@ -34,3 +36,18 @@ def test_can_save_model(db_session): def test_db_is_empty(db_session): assert not db_session.query(User).all() + + +def test_requires_override_model_base(testdir): + + testdir.makepyfile( + """ + def test_model_base(model_base): + pass + """ + ) + result = testdir.runpytest() + assert result.ret == 1 + result.stdout.fnmatch_lines( + ["*NotImplementedError*"] + )