Skip to content

Commit

Permalink
Merge pull request #7 from kooba/test-fixtures-package
Browse files Browse the repository at this point in the history
Moved modules to a package.
  • Loading branch information
mattbennett authored Sep 2, 2016
2 parents 346bb35 + 60be7ff commit 598a914
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions nameko_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from nameko_sqlalchemy.database_session import ( # noqa: F401
DatabaseSession, DB_URIS_KEY, Session
)
File renamed without changes.
8 changes: 2 additions & 6 deletions pytest_fixtures.py → nameko_sqlalchemy/pytest_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
author='onefinestay',
author_email='[email protected]',
url='http://github.com/onefinestay/nameko-sqlalchemy',
py_modules=['nameko_sqlalchemy'],
packages=['nameko_sqlalchemy'],
install_requires=[
"nameko>=2.0.0",
"sqlalchemy"
Expand All @@ -23,7 +23,7 @@
},
entry_points={
'pytest11': [
'pytest_fixtures=pytest_fixtures'
'nameko_sqlalchemy=nameko_sqlalchemy.pytest_fixtures'
]
},
zip_safe=True,
Expand Down
17 changes: 17 additions & 0 deletions test/test_pytest_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

pytest_plugins = "pytester"


class Base(object):
pass
Expand Down Expand Up @@ -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*"]
)

0 comments on commit 598a914

Please sign in to comment.