Skip to main content
PyPI version Python versions 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’ and python : 3.5, 3.6

Installation

You can install “pytest-ponyorm” via pip from PyPI:

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

Usage

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 :

[pytest]
    PONY_DB=path.models.main

Then just apply the pony marker :

# 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 at ending.

    # 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.

About Reseting Database:

Test database tables are dropped/recreate before the test SESSION.

Initialy this plugin did drop/recreate table for each test. Due to perfomance reason, this has changed. Now tables are cleared but not dropped.

Sql sequences like “auto PrimaryKey” will also be reset but actually, it’s only supported for PostgreSQL and Sqlite. For other databases, Primarykey might not start at 1 for each test. This has to be considered when writing tests.

About Fixtures :

Fixtures should not use db_session decorator or context manager. Each test is automaticaly run inside a db_session and each operation inside fixtures will be commited at test start.

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.

Changelog

0.3.1 :
  • sql sequence reset for postgre and sqlite

  • testing py35/36 and pg/sqlite

0.3.0 :
  • made faster with just deleting database entries after each test

  • no drop/recreate

  • db_session splitted into 2 hooks, not anymore in a fixture

0.2.9 :
  • add fixture autocommit before run test

0.2.0 :
  • add marker

0.1.5 :
  • add db_session for each test

0.1.0 :
  • auto clear database

Metadata

Release files for pytest-ponyorm 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-ponyorm 0.3.3
File Size Uploaded
pytest-ponyorm-0.3.3.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-ponyorm 0.3.3
File Interpreter ABI Platform
pytest_ponyorm-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.8 kB

Release files / pytest-ponyorm-0.3.3.tar.gz

Download URL pytest-ponyorm-0.3.3.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8c17bf7cdb339d55bbe83d03e173bcf68d619b539bd957d12968834ca7e8b75b
BLAKE2b-256 checksum
How to use checksums
2c3e74746d08ef121a88808159acbb6af00e3af0023efac81acc23ae49d6569b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

Release files / pytest_ponyorm-0.3.3-py3-none-any.whl

Download URL pytest_ponyorm-0.3.3-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e387ce9572b64a63c9aa2b74391c24a21ef75e855c1b390fb5e7d862df0b25fb
BLAKE2b-256 checksum
How to use checksums
b8d110de94c4363d2f13957e6f5659cef9294add8215cf401118fed771693347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

1 release file

0.2.8

2 release files

0.2.4

3 release files

0.2.3

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page