interface_tests
A dummy package to see how to unit-test multiple implementations of the same interface with a single set of tests
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.4%) to scientific vocabulary
Repository
A dummy package to see how to unit-test multiple implementations of the same interface with a single set of tests
Basic Info
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
- Releases: 0
Metadata Files
README.md
A prototype for flexibly testing multiple implementations of the same interface
This repository is a barebone package to explore how to implement reusable tests for multiple implementations of the same interface.
The structure is as follows
- src/mypkg has multiple modules module_a, module_b, module_c. They all implement the same interface: they contain a class MyClassX that has a method method.
- Each module has its own test directory, ie src/mypkg/module_a/tests.
- In each module-specific test, we'd like to make it as easy as possible to run standard tests for the implementation of the interface. This is done with
python
from mypkg.interface_tests import test_interface
- pytest executes test_interface when it discovers the test file
- This led to the following requirements:
- we need to dynamically determine which module to test from the calling test function alone
- for any user running the test, they may not have installed all modules that implement the interface. Therefore, we have to dynamically determine which tests to run
Implementation
I built this functionality with pytest fixtures and hooks.
In src/mypkg/interface_tests.py
- define all tests for the interface
- map from calling functions to modules to be imported and classes to be passed to the test
In src/mypkg/conftest.py
- import things defined in interface_tests.py
- define fixture run_interface_tests, which takes a dynamic implementationclass and runs all tests on that
- `pytestgeneratetestshook detects the functiontestinterface`, and dynamically returns the class to be tested that implements the interface. If the requested module is not importable, the test is skipped.
Installation
To install mypkg from GitHub repository, do:
console
git clone git@github.com:f-fhafner/mypkg.git
cd mypkg
python -m pip install .
For developers
```console git clone git@github.com:f-fhafner/mypkg.git cd mypkg python -m venv .venv source .venv/bin/activate python -m pip install -e .
run the tests
pytest -v -s ```
Credits
This package was created with Copier and the NLeSC/python-template.
Owner
- Login: f-hafner
- Kind: user
- Repositories: 3
- Profile: https://github.com/f-hafner
Citation (CITATION.cff)
# YAML 1.2
---
cff-version: "1.2.0"
title: "mypkg"
authors:
- family-names: Hafner
given-names: Flavio
orcid: "https://orcid.org/0000-0000-0000-0000"
date-released: 2025-03-20
version: "0.1.0"
repository-code: "https://github.com/f-fhafner/mypkg"
keywords:
- "pytest"
- "interface"
message: "If you use this software, please cite it using these metadata."
GitHub Events
Total
- Issues event: 2
- Issue comment event: 1
- Push event: 6
- Create event: 3
Last Year
- Issues event: 2
- Issue comment event: 1
- Push event: 6
- Create event: 3
Committers
Last synced: 10 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Flavio Hafner | 5****r | 13 |
| NLeSC Python template | n****e | 3 |
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 3
- Total pull requests: 0
- Average time to close issues: 5 days
- Average time to close pull requests: N/A
- Total issue authors: 2
- Total pull request authors: 0
- Average comments per issue: 0.33
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 2
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 0
- Average time to close issues: 5 days
- Average time to close pull requests: N/A
- Issue authors: 2
- Pull request authors: 0
- Average comments per issue: 0.33
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 2
- Bot pull requests: 0
Top Authors
Issue Authors
- github-actions[bot] (2)
- f-hafner (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/checkout v4 composite
- citation-file-format/cffconvert-github-action 2.0.0 composite