Quickstart

You can install latest version from pypi:

pip3 install testoot

And use library such way:

# regress is the helper fixture easy to setup
def test_simple(testoot: Testoot):
    result = {'a': 1}
    testoot.test(result)  # Commit first time

    result2 = {'a': 1}
    testoot.test(result2)  # Ok. No object result changes

    result3 = {'a': 3}  # Try commit change. Raised the AssertionError
    with pytest.raises(AssertionError) as e:
        testoot.test(result3)

Pytest configuration is the quite simple:

import pytest

from testoot.ext.pytest import PytestContext, register_addoption
from testoot.testoot import Testoot
from testoot.pub import DefaultBaseTestoot


def pytest_addoption(parser):
    register_addoption(parser)


@pytest.fixture(scope='module')
def testoot_instance():
    testoot = DefaultBaseTestoot()
    testoot.storage.ensure_exists()
    yield testoot


@pytest.fixture(scope='function')
def testoot(testoot_instance, request):
    fixture = Testoot(testoot_instance,
                      PytestContext(request))
    yield fixture

Basically DefaultTestoot is the configured class:

from testoot.pub import Testoot, AskCanonizePolicy, PickleSerializer, \
    LocalDirectoryStorage, DefaultTestoot, ConsoleUserInteraction

class DefaultTestoot(Testoot):
    def __init__(self):
        super().__init__(
            storage=LocalDirectoryStorage('.testoot'),
            serializer=PickleSerializer(),
            canonize_policy=AskCanonizePolicy(ConsoleUserInteraction())),
        )

It uses local filesystem storage in .testoot directory in storage parameter.

All objects are dumped with pickle serializer testoot.pub.PickleSerializer, which is supports almost all Python objects, but has only binary representantion in files. It’ll be difficult to merge binary changes in the favourite VCS without running code. You can find other serializers in Serializers page.

Parameter canonize_policy controls behavior when we met result test conflict:

  • testoot.pub.AskCanonizePolicy (default) with –canonize pytest flag asks user approval for canonizing. If user refuses it skips for later and raises an error in assert then. For supporing –canonize flag testoot.ext.pytest.register_addoption() have to be called in conftest.py.

  • testoot.pub.NoCanonizePolicy always raises an error in assert.