Package: pytest-budosystems
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 aRepository.  However, you get 21 ready-to-use tests for free to
validate your implementation of aRepository.UsageThe assumption here is that you’re using this package to add tests for an implementation of a feature for Budo Systems.Step 1. InstallationFrom your project environment, first you need to install the package.  There are several options for this.  Here are
but a few examples.Install directly withpip:🐚 shellpipinstallpytest-budosystemsAdd torequirements.txt, and install using that file:📝requirements.txtbudosystems-core
pytest-budosystems🐚 shellpipinstall-rrequirements.txtAdd tosetup.cfg, and reinstall your project:📝setup.cfg[metadata]name=my-budosystems-projectversion=0.0.2description=My implementation of a Budo Systems feature.[options]python_requires=>= 3.9packages=find_namespace:package_dir==srcinstall_requires=budosystems-coreanother-required-packagesomething-else-needed[options.packages.find]where=src[options.extras_require]test=pytestpytest-budosystems🐚 shellpipinstall-U-e.Step 2. Add to your test suiteTo use this test suite to test your implementation of abudosystems.storage.repository.Repository, you’ll need to
create a test class that inherits frombudosystems.xtra.pytest_suite.repository.AbstractTestRepositoryand override a few fixture methods.The only required fixture method isrepo_class.  It’s an abstract method with the following specs:@abstractmethod@fixture(scope="class")defrepo_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 arerepo_argsandrepo_inaccessible.  Here’s how they are defined inAbstractTestRepository@fixture(scope="class")defrepo_args(self)->dict[str,Any]:"""Returns implementation specific arguments to instantiate the implementation of
    `Repository` being tested."""return{}@fixture(scope="class")defrepo_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 ExampleA minimal example can be found in the test suite for Budo Systems Core:📝test_dict_repository.pyfrompytestimportfixturefrombudosystems.xtra.pytest_suite.repositoryimportAbstractTestRepositoryfrombudosystems.storage.repositoryimportRepositoryfrombudosystems.storage.dict_repositoryimportDictRepositoryclassTestDictRepository(AbstractTestRepository):@fixture(scope="class")defrepo_class(self)->type[Repository]:returnDictRepositoryA More Complex ExampleAn example that overrides all the methods listed above can be found in the test suite for Budo Systems SQLite Storage:📝test_repository.pyfrompytestimportfixtureimportsqlite3fromtypingimportAnyfrombudosystems.xtra.pytest_suite.repositoryimportAbstractTestRepositoryfrombudosystems.storage.repositoryimportRepositoryfrombudosystems.xtra.sqlite3_storage.repositoryimportSQLite3RepositoryclassTestSQLite3Repository(AbstractTestRepository):@fixture(scope="class")defrepo_class(self)->type[Repository]:returnSQLite3Repository@fixture(scope="class")defrepo_args(self)->dict[str,Any]:return{"con":sqlite3.connect(":memory:")}@fixture(scope="class")defrepo_inaccessible(self,repo_class:type[Repository])->Repository:con=sqlite3.connect(":memory:")repo=repo_class(con=con)con.close()returnrepoStep 3. Test!Runpytestand get your results.