Skip to main content

PonyORM in Pytest

Project description

==============
pytest-ponyorm
==============

.. image:: https://img.shields.io/pypi/v/pytest-ponyorm.svg
:target: https://pypi.python.org/pypi/pytest-ponyorm
:alt: PyPI version

.. image:: https://img.shields.io/pypi/pyversions/pytest-ponyorm.svg
:target: https://pypi.python.org/pypi/pytest-ponyorm
:alt: Python versions

.. image:: https://travis-ci.org/jgirardet/pytest-ponyorm.svg?branch=master
:target: https://travis-ci.org/jgirardet/pytest-ponyorm
:alt: See Build Status on Travis CI

PonyORM in Pytest

----

Plugin for use `Pony ORM`_ in `Pytest`_.

This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.


Features
--------

* Access Database instance (db) via *ponydb* fixture
* Mark tests to auto allow use of *pony.orm.db_session*
* Database is by default cleared after each test
* Database reset can be cancelled for test/class/module


Requirements
------------

Tested from `Pony ORM`_ >= '0.7.3'


Installation
------------

You can install "pytest-ponyorm" via `pip`_ from `PyPI`_::

$ pip install pytest-ponyorm
or
$ pipenv install -d pytest-ponyorm


Usage
-----

.. warning:: By default, database is cleared after each test. You must never use it in a production environnement. This plugin doesn't change the database config.It's you'job to create the testing environnement and change database params. You may use _`pytest-env` to add environnement variable at pytest run, and check this in your code to set testing environnement.

First, configure PONY_DB in pytest.ini. PonyORM main Database instance module location must be specified in pytest.ini to make it work : for example if db is in /path/models/main.py, you must configure like this :

.. code-block:: ini

[pytest]
PONY_DB=path.models.main

Then just apply the pony marker :

.. code-block:: python

# models.py
db = Database()

# test.py

@pytest.mark.pony
def my_test(ponydb):
new_mod = ponydb.Mymodel(name="me",...)

You can mark a class or function with @pytest.mark.pony or the whole module with pytestmark = pytest.mark.pony

The marker *pony* takes one argument : *reset_db*, default is True. In this case the marked test doesn't reset the database before running.

.. code-block:: python

# test.py
pytestmark = pytest.mark.pony # marks all tests of the module

def test1:
pass

def test2:
pass

@pytest.mark.pony(reset_db=False)
def test 3:
pass

# test3 will use database in the state that test2 left it.



Contributing
------------
Contributions are very welcome. Tests can be run with `tox`_, please ensure
the coverage at least stays the same before you submit a pull request.

License
-------

Distributed under the terms of the `GNU GPL v3.0`_ license, "pytest-ponyorm" is free and open source software


Issues
------

If you encounter any problems, please `file an issue`_ along with a detailed description.

.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`MIT`: http://opensource.org/licenses/MIT
.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause
.. _`GNU GPL v3.0`: http://www.gnu.org/licenses/gpl-3.0.txt
.. _`Apache Software License 2.0`: http://www.apache.org/licenses/LICENSE-2.0
.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _`file an issue`: https://github.com/jgirardet/pytest-ponyorm/issues
.. _`pytest`: https://github.com/pytest-dev/pytest
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.python.org/pypi/pip/
.. _`PyPI`: https://pypi.python.org/pypi
.. _`Pony ORM`: http://ponyorm.com
.. _`pytest-env`: https://github.com/MobileDynasty/pytest-env

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-ponyorm-0.2.8.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_ponyorm-0.2.8-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-ponyorm-0.2.8.tar.gz.

File metadata

File hashes

Hashes for pytest-ponyorm-0.2.8.tar.gz
Algorithm Hash digest
SHA256 43debf43cf56829a1f9b4dd4b33355172d4ef584b2c064a5975d588d40fd2bf1
MD5 5bc2477a6e322e6ad114c0f91d528f16
BLAKE2b-256 b208736600ce91c0ef0bc81706f45bbf1c361e14792cb0d96d1608c146365fc2

See more details on using hashes here.

File details

Details for the file pytest_ponyorm-0.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_ponyorm-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d0cc8f725a93b29c5e1e60e526cb929fd2f296928dfc5bf9f2a3c0df0889f333
MD5 368778e3d8e1fa774584c97a7a5bdc11
BLAKE2b-256 1bd98db3d3bc06d7b8cbda06593a4ff6b78f3444ba6130923f464e7abcdedae1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page