PyGuard
A python auto test runner inspired by the guard project.
A simple example that runs all the tests when a file is modified would look something like this:
from filewatch import file_updated_subject, Watcher
from pyguard import guardian, GuardianObserver, RegexRule, RuleManager
manager = RuleManager(cmd='py.test pyguard')
manager.register_rules(
RegexRule(regex=r'.*/pyguard/.*'),
)
guardian.register_manager(manager)
# Set up our file observer
file_updated_subject.register_observer(GuardianObserver())
# Get our watcher going
watcher = Watcher()
watcher.run()
Any RuleManager that you create will execute the given command whenever a registered rule matches a supplied file path.
To make things a little more granular, we can register a different set of rules. i.e.
...
manager = RuleManager(cmd='py.test pyguard/tests/test_{test_name}.py')
manager.register_rules(
RegexRule(regex=r'.*/rules.py', cmd_augmentation={'test_name' : 'rules'}),
RegexRule(regex=r'.*/core.py', cmd_augmentation={'test_name' : 'guardian'}),
)
guardian.register_manager(manager)
...
To enforce a particular naming convention we can take things even further using named groups within the regex itself. If we have say a views.py and we know that the tests for said views exist in test_views.py, then we can simple use:
...
manager = RuleManager(cmd='py.test pyguard/tests/test_{test_name}.py')
manager.register_rules(
RegexRule(regex=r'.*/(?P<test_name>views).py'),
)
guardian.register_manager(manager)
...
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pyguard-0.0.4.tar.gz.
File metadata
- Download URL: pyguard-0.0.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79af61547dae5ee8338f2a961349c9fa54bd8be5a4597195da72b344253e680f
|
|
| MD5 |
84581672eafd61419e2633f8bcef65d2
|
|
| BLAKE2b-256 |
f1b5b130b4447deeb35fe0b53f36fffe4450a2b54ef8f96a36f72a461824155c
|