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.
Install directly with pip:
🐚 shell
pip install pytest-budosystemsAdd to requirements.txt, and install using that file:
📝 requirements.txt
budosystems-core pytest-budosystems🐚 shell
pip install -r requirements.txtAdd 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.
Metadata
Release files for pytest-budosystems 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-budosystems-0.3.0.tar.gz | 83.1 kB | Without provenance | Details for pytest-budosystems-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_budosystems-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_budosystems-0.3.0-py3-none-any.whl |
Total release size: 97.3 kB
Release files / pytest-budosystems-0.3.0.tar.gz
| Download URL | pytest-budosystems-0.3.0.tar.gz |
|---|---|
| Size | 83.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92623a6c0d688f2e689e701fb4cb27e949e7cc736787a51e94af0d83a16a1b71
|
|
BLAKE2b-256 checksum How to use checksums |
a8d301c971ee100ae0306fb1e01cab4b2451e47040fb8283361c5676e80aa296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / pytest_budosystems-0.3.0-py3-none-any.whl
| Download URL | pytest_budosystems-0.3.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b21063ada4e6a592b64e6dce1ce7f50935a29ed9b63edbb0ec83d987e54a7256
|
|
BLAKE2b-256 checksum How to use checksums |
1c87693089799be286c99eda142d36ca54cdb62834113557773d8c7ee40e4ce6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for pytest-budosystems 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.