Feather Test
Feather Test is an event-driven testing framework for Python, inspired by the unittest module but with enhanced features for parallel execution and customizable reporting.
Features
- Event-driven architecture for flexible test execution and reporting
- Parallel test execution for improved performance
- Customizable reporters for tailored test output
- Command-line interface similar to unittest for ease of use
- Support for custom events during test execution
Installation
You can install Feather Test using pip:
pip install feather-test
Usage
Command-line Interface
Feather Test can be run from the command line, similar to unittest:
feather [options] [start_directory]
Options:
-f,--failfast: Stop on first fail or error-c,--catch: Catch control-C and display results-k PROCESSES,--processes PROCESSES: Number of processes to use-r REPORTER,--reporter REPORTER: Reporter to use (default: DefaultReporter)-p PATTERN,--pattern PATTERN: Pattern to match test files (default: test*.py)
You can also pass reporter-specific arguments by prefixing them with the reporter name:
feather -r CustomReporter --customreporter-output-file report.txt --customreporter-verbose
Writing Tests
Tests are written similarly to unittest, but inherit from `EventDrivenTestCase`:
from feather_test import EventDrivenTestCase
class MyTest(EventDrivenTestCase):
def test_example(self):
self.assertTrue(True)
def test_custom_event(self):
self.event_publisher.publish('custom_event', self.correlation_id,
data='Custom event data')
self.assertEqual(1, 1)
Custom Reporters
You can create custom reporters by inheriting from `BaseReporter`:
from feather_test.event_driven_unittest import BaseReporter
class CustomReporter(BaseReporter):
def __init__(self, output_file=None, verbose=False):
self.output_file = output_file
self.verbose = verbose
self.total_tests = 0
self.passed_tests = 0
def on_test_run_start(self, correlation_id, run_id):
print(f"Test run started (Run ID: {run_id}")
def on_test_success(self, correlation_id, test_name, class_name, module_name):
self.passed_tests += 1
if self.verbose:
print(f"Test passed: {module_name}.{class_name}.{test_name}")
def on_test_run_end(self, correlation_id, run_id):
print(f"Tests completed. Passed: {self.passed_tests}/{self.total_tests}")
if self.output_file:
with open(self.output_file, 'w') as f:
f.write(f"Passed: {self.passed_tests}/{self.total_tests}")
Programmatic Usage
You can also use Feather Test programmatically:
from feather_test import EventDrivenTestRunner
import unittest
def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(MyTest))
runner = EventDrivenTestRunner(processes=2, verbosity=2, reporters=['CustomReporter'])
runner.run(suite)
if __name__ == '__main__':
run_tests()
Events
Feather Test emits various events during the test execution process. Custom reporters can listen for these events to provide detailed and customized test reports. Here's a list of all events that can be emitted:
-
test_run_start: Emitted when the entire test run begins.- Data:
run_id
- Data:
-
test_run_end: Emitted when the entire test run completes.- Data:
run_id
- Data:
-
test_start: Emitted when an individual test method starts.- Data:
test_name,class_name,module_name
- Data:
-
test_end: Emitted when an individual test method ends.- Data:
test_name,class_name,module_name
- Data:
-
test_success: Emitted when a test passes successfully.- Data:
test_name,class_name,module_name
- Data:
-
test_failure: Emitted when a test fails.- Data:
test_name,class_name,module_name,failure(error message and traceback)
- Data:
-
test_error: Emitted when a test raises an unexpected exception.- Data:
test_name,class_name,module_name,error(error message and traceback)
- Data:
-
test_skip: Emitted when a test is skipped.- Data:
test_name,class_name,module_name,reason
- Data:
-
test_setup: Emitted when the setUp method of a test case is called.- Data:
test_name
- Data:
-
test_teardown: Emitted when the tearDown method of a test case is called.- Data:
test_name
- Data:
-
test_run_error: Emitted if there's an error in the test running process itself.- Data:
error(error message and traceback)
- Data:
Custom events can also be emitted from within tests using the self.event_publisher.publish() method. These events will be passed to reporters with whatever data is provided.
When creating custom reporters, you can define methods to handle these events. The method names should be in the format on_<event_name>. For example, to handle the test_start event, you would define an on_test_start method in your reporter class.
Emitting Custom Events
You can emit custom events from within your tests using the event_publisher:
class MyTest(EventDrivenTestCase):
def test_example(self):
self.event_publisher.publish('my_custom_event', self.correlation_id,
custom_data='Some interesting information')
self.assertTrue(True)
Custom reporters can then handle these events by defining an on_my_custom_event method.
Third-Party Extensions for Feather Test
Feather Test supports third-party TestServers and Reporters, allowing the community to extend the framework's functionality.
Naming Convention
All third-party packages for Feather Test must follow this specific naming convention:
-
For TestServers:
- Package name:
feather-test-server-<name> - Python module name:
feather_test_server_<name> - Main class name:
<Name>TestServer
- Package name:
-
For Reporters:
- Package name:
feather-test-reporter-<name> - Python module name:
feather_test_reporter_<name> - Main class name:
<Name>Reporter
- Package name:
This convention helps maintain consistency, avoid naming conflicts, and makes the purpose of each package immediately clear.
Creating a Third-Party TestServer Package
- Create a new Python package named
feather-test-server-<name>(e.g.,feather-test-server-custom). - Name your Python module
feather_test_server_<name>(e.g.,feather_test_server_custom). - Implement your main TestServer class as
<Name>TestServer(e.g.,CustomTestServer) by subclassingfeather_test.test_server.TestServer. - Publish your package to PyPI.
Example structure:
feather-test-server-custom/
feather_test_server_custom/
__init__.py
custom_test_server.py
setup.py
README.md
LICENSE
Creating a Third-Party Reporter Package
- Create a new Python package named
feather-test-reporter-<name>(e.g.,feather-test-reporter-custom). - Name your Python module
feather_test_reporter_<name>(e.g.,feather_test_reporter_custom). - Implement your main Reporter class as
<Name>Reporter(e.g.,CustomReporter) by subclassingfeather_test.reporters.base_reporter.BaseReporter. - Publish your package to PyPI.
Example structure:
feather-test-reporter-custom/
feather_test_reporter_custom/
__init__.py
custom_reporter.py
setup.py
README.md
LICENSE
Using Third-Party Extensions
After installing third-party packages, you can use them as follows:
-
Command line:
feather -s CustomTestServer -r CustomReporter -
Programmatically:
from feather_test import EventDrivenTestRunner runner = EventDrivenTestRunner(processes=2, reporters=['CustomReporter'], server='CustomTestServer') runner.discover_and_run('tests')
Note: When using third-party extensions, you only need to specify the class name. The framework will automatically determine the correct module to import based on the naming convention.
For more details on creating custom TestServers and Reporters, refer to the respective documentation sections.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Metadata
Release files for feather-test 0.1.4
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 |
|---|---|---|---|---|
| feather_test-0.1.4.tar.gz | 20.2 kB | Without provenance | Details for feather_test-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| feather_test-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for feather_test-0.1.4-py3-none-any.whl |
Total release size: 44.5 kB
Release files / feather_test-0.1.4.tar.gz
| Download URL | feather_test-0.1.4.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9743cbf3193279f2e69bcd38ec54dbe40980d31c441502b908dfe7044f376dae
|
|
BLAKE2b-256 checksum How to use checksums |
3be8ebe8c2d526316489109e4f5837cb894b23b320602676629fca144c6c290b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.0 Darwin/23.6.0
|
Release files / feather_test-0.1.4-py3-none-any.whl
| Download URL | feather_test-0.1.4-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8058f8dc5cbe7727451d1e8c6b676547686454acb212094e416de3a196d2237
|
|
BLAKE2b-256 checksum How to use checksums |
4b5a10a66c5aa657f1e3b0c00227198b8e8941991044d5cc4b54ee47484403e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.0 Darwin/23.6.0
|
Security for feather-test 0.1.4
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.