Skip to content

Commit

Permalink
Merge pull request #2 from jeancochrane/rename-plugin
Browse files Browse the repository at this point in the history
Rename the plugin to 'pytest-flask-sqlalchemy'
  • Loading branch information
jeancochrane authored Aug 2, 2018
2 parents 4f3111e + edf6d84 commit 4283cb8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.egg-info
__pycache__
.pytest_cache
.cache
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pytest-flask-sqlalchemy-transactions
# pytest-flask-sqlalchemy

[![Build Status](https://travis-ci.org/jeancochrane/pytest-flask-sqlalchemy-transactions.svg?branch=master)](https://travis-ci.org/jeancochrane/pytest-flask-sqlalchemy-transactions) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Django.svg)
[![Build Status](https://travis-ci.org/jeancochrane/pytest-flask-sqlalchemy.svg?branch=master)](https://travis-ci.org/jeancochrane/pytest-flask-sqlalchemy) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Django.svg)

A [pytest](https://docs.pytest.org/en/latest/) plugin providing fixtures for running tests in
transactions using [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/latest/).
Expand All @@ -13,6 +13,7 @@ transactions using [Flask-SQLAlchemy](http://flask-sqlalchemy.pocoo.org/latest/)
- [Installation](#installation)
- [From PyPi](#from-pypi)
- [Development version](#development-version)
- [Supported backends](#supported-backends)
- [Configuration](#configuration)
- [Conftest setup](#conftest-setup)
- [Test configuration](#test-configuration)
Expand Down Expand Up @@ -125,7 +126,7 @@ def test_transaction_doesnt_persist(db_session):
Install using pip:

```
pip install pytest-flask-sqlalchemy-transactions
pip install pytest-flask-sqlalchemy
```

Once installed, pytest will detect the plugin automatically during test collection.
Expand All @@ -137,8 +138,8 @@ documentation](https://docs.pytest.org/en/latest/plugins.html?highlight=plugins)
Clone the repo from GitHub and switch into the new directory:

```
git clone [email protected]:jeancochrane/pytest-flask-sqlalchemy-transactions.git
cd pytest-flask-sqlalchemy-transactions
git clone [email protected]:jeancochrane/pytest-flask-sqlalchemy.git
cd pytest-flask-sqlalchemy
```

You can install using pip:
Expand All @@ -147,6 +148,20 @@ You can install using pip:
pip install .
```

### <a name="supported-backends">Supported backends</a>

So far, pytest-flask-sqlalchemy has been most extensively tested against
PostgreSQL 9.6. It should theoretically work with any backend that is supported
by SQLAlchemy, but Postgres is the only backend that is currently tested by the
test suite.

Official support for SQLite and MySQL is [planned for a future
release](https://github.com/jeancochrane/pytest-flask-sqlalchemy/issues/3).
In the meantime, if you're using one of those backends and you run in to
problems, we would greatly appreciate your help! [Open an
issue](https://github.com/jeancochrane/pytest-flask-sqlalchemy/issues/new) if
something isn't working as you expect.

## <a name="configuration"></a>Configuration

### <a name="conftest-setup"></a>Conftest setup
Expand Down Expand Up @@ -448,6 +463,10 @@ whose blog post ["Delightful testing with pytest and
Flask-SQLAlchemy"](http://alexmic.net/flask-sqlalchemy-pytest/) helped
establish the basic approach on which this plugin builds.

Many thanks to [Igor Ghisi](https://github.com/igortg/), who donated the PyPi
package name. Igor had been working on a similar plugin and proposed combining
efforts. Thanks to Igor, the plugin name is much stronger.

## <a name="copyright"></a>Copyright

Copyright (c) 2018 Jean Cochrane and DataMade. Released under the MIT License.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def _db():
Session object that can access the test database. If the user hasn't defined
that fixture, raise an error.
'''
msg = ("_db fixture not defined. The pytest-flask-sqlalchemy-transactions plugin " +
"requires you to define a _db fixture that returns a SQLAlchemy session " +
msg = ("_db fixture not defined. The pytest-flask-sqlalchemy plugin " +
"requires you to define a _db fixture that returns a SQLAlchemy Session " +
"with access to your test database. For more information, see the plugin " +
"documentation: " +
"https://github.com/jeancochrane/pytest-flask-sqlalchemy-transactions#conftest-setup")
"https://github.com/jeancochrane/pytest-flask-sqlalchemy#conftest-setup")

raise NotImplementedError(msg)

Expand Down
File renamed without changes.
18 changes: 6 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
'''
pytest-flask-sqlalchemy-transactions
====================================
Run tests in transactions using pytest, Flask, and SQLAlchemy.
'''
from setuptools import setup


Expand All @@ -12,16 +6,16 @@ def readme():
return f.read()

setup(
name='pytest-flask-sqlalchemy-transactions',
name='pytest-flask-sqlalchemy',
author='Jean Cochrane',
author_email='[email protected]',
url='https://github.com/jeancochrane/pytest-flask-sqlalchemy-transactions',
description='Run tests in transactions using pytest, Flask, and SQLalchemy.',
url='https://github.com/jeancochrane/pytest-flask-sqlalchemy',
description='A pytest plugin for preserving test isolation in Flask-SQlAlchemy using database transactions.',
long_description=readme(),
long_description_content_type='text/markdown',
license='MIT',
version='1.0.1',
packages=['transactions'],
version='1.0.0',
packages=['pytest_flask_sqlalchemy'],
install_requires=['pytest>=3.2.1',
'pytest-mock>=1.6.2',
'SQLAlchemy>=1.2.2',
Expand All @@ -42,7 +36,7 @@ def readme():
# Make the package available to pytest
entry_points={
'pytest11': [
'pytest-flask-sqlalchemy-transactions = transactions.plugin',
'pytest-flask-sqlalchemy = pytest_flask_sqlalchemy.plugin',
]
},
)
2 changes: 1 addition & 1 deletion tests/_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
else:
DB_OPTS = sa.engine.url.make_url(DB_CONN).translate_connect_args()

pytest_plugins = ['pytest-flask-sqlalchemy-transactions']
pytest_plugins = ['pytest-flask-sqlalchemy']


@pytest.fixture(scope='session')
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

# This import prevents SQLAlchemy from throwing an AttributeError
Expand All @@ -14,7 +16,7 @@ def conftest():
Load configuration file for the tests to a string, in order to run it in
its own temporary directory.
'''
with open('tests/_conftest.py', 'r') as conf:
with open(os.path.join('tests', '_conftest.py'), 'r') as conf:
conftest = conf.read()

return conftest
Expand Down
6 changes: 3 additions & 3 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_mocked_sessionmakers(db_testdir):
db_testdir.makepyfile("""
def test_mocked_sessionmakers(db_session):
from collections import namedtuple, Counter
assert str(namedtuple).startswith("<transactions.fixtures._session.<locals>.FakeSessionMaker")
assert str(Counter).startswith("<transactions.fixtures._session.<locals>.FakeSessionMaker")
assert str(namedtuple).startswith("<pytest_flask_sqlalchemy.fixtures._session.<locals>.FakeSessionMaker")
assert str(Counter).startswith("<pytest_flask_sqlalchemy.fixtures._session.<locals>.FakeSessionMaker")
""")

result = db_testdir.runpytest()
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_missing_db_fixture(testdir):
else:
DB_OPTS = sa.engine.url.make_url(DB_CONN).translate_connect_args()
pytest_plugins = ['pytest-flask-sqlalchemy-transactions']
pytest_plugins = ['pytest-flask-sqlalchemy']
@pytest.fixture(scope='session')
Expand Down

0 comments on commit 4283cb8

Please sign in to comment.