Skip to main content

Budo Systems is a martial arts school management system. This module is the Budo Systems Pytest Plugin.

Project description

This add-on to the Budo Systems platform creates a standardized test suite for modules that implement services abstracted in Budo Systems Core (project, docs).

This early version only provides a test suite for a Repository. However, you get 21 ready-to-use tests for free to validate your implementation of a Repository.

Usage

The assumption here is that you’re using this package to add tests for an implementation of a feature for Budo Systems.

Step 1. Installation

From your project environment, first you need to install the package. There are several options for this. Here are but a few examples.

  1. Install directly with pip:

    🐚 shell

    pip install pytest-budosystems
  2. Add to requirements.txt, and install using that file:

    📝 requirements.txt

    budosystems-core
    pytest-budosystems

    🐚 shell

    pip install -r requirements.txt
  3. Add to setup.cfg, and reinstall your project:

    📝 setup.cfg

    [metadata]
    name = my-budosystems-project
    version = 0.0.2
    description = My implementation of a Budo Systems feature.
    
    [options]
    python_requires = >= 3.9
    packages = find_namespace:
    package_dir =
        =src
    
    install_requires =
        budosystems-core
        another-required-package
        something-else-needed
    
    [options.packages.find]
    where = src
    
    [options.extras_require]
    test =
        pytest
        pytest-budosystems

    🐚 shell

    pip install -U -e .

Step 2. Add to your test suite

To use this test suite to test your implementation of a budosystems.storage.repository.Repository, you’ll need to create a test class that inherits from budosystems.xtra.pytest_suite.repository.AbstractTestRepository and override a few fixture methods.

The only required fixture method is repo_class. It’s an abstract method with the following specs:

@abstractmethod
@fixture(scope="class")
def repo_class(self) -> type[Repository]:
    """Returns the class for the implementation of `Repository` being tested."""

Your testing needs may require you to override some other fixture methods. The two most likely candidates are repo_args and repo_inaccessible. Here’s how they are defined in AbstractTestRepository

@fixture(scope="class")
def repo_args(self) -> dict[str, Any]:
    """Returns implementation specific arguments to instantiate the implementation of
    `Repository` being tested."""
    return {}

@fixture(scope="class")
def repo_inaccessible(self, repo_class: type[Repository]) -> Repository:
    """
    Returns an instance of the implementation of `Repository` with improper connection.
    """
    pytest.skip(f"No 'inaccessible' implementation of {str(repo_class)}")

Minimal Example

A minimal example can be found in the test suite for Budo Systems Core:

📝 test_dict_repository.py

from pytest import fixture
from budosystems.xtra.pytest_suite.repository import AbstractTestRepository
from budosystems.storage.repository import Repository
from budosystems.storage.dict_repository import DictRepository

class TestDictRepository(AbstractTestRepository):

    @fixture(scope="class")
    def repo_class(self) -> type[Repository]:
        return DictRepository

A More Complex Example

An example that overrides all the methods listed above can be found in the test suite for Budo Systems SQLite Storage:

📝 test_repository.py

from pytest import fixture
import sqlite3
from typing import Any

from budosystems.xtra.pytest_suite.repository import AbstractTestRepository
from budosystems.storage.repository import Repository
from budosystems.xtra.sqlite3_storage.repository import SQLite3Repository

class TestSQLite3Repository(AbstractTestRepository):

    @fixture(scope="class")
    def repo_class(self) -> type[Repository]:
        return SQLite3Repository

    @fixture(scope="class")
    def repo_args(self) -> dict[str, Any]:
        return {"con": sqlite3.connect(":memory:")}

    @fixture(scope="class")
    def repo_inaccessible(self, repo_class: type[Repository]) -> Repository:
        con = sqlite3.connect(":memory:")
        repo = repo_class(con=con)
        con.close()
        return repo

Step 3. Test!

Run pytest and get your results.

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-budosystems-0.3.0.tar.gz (83.1 kB view hashes)

Uploaded Source

Built Distribution

pytest_budosystems-0.3.0-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

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