Skip to content

Scripting

You can use Baygon as a library to write your own test runner. This is useful if you want to write your own test runner or if you want to use Baygon in a CI/CD pipeline.

Here is an example of a test runner using Baygon:

from pathlib import Path
from baygon.suite import SuiteExecutor, SuiteService

service = SuiteService()
report = service.run(
    data={
        'filters': {'uppercase': True},
        'tests': [{
            'args': ['--version'],
            'stderr': [{'contains': 'VERSION'}],
        }],
    },
    executable=Path('myapp'),
)

assert report.failures == 0

report.as_dict() returns the same data as the --report file. Limits and test selection are available too:

context = service.load(path='tests.yml')
context = context.select(ids=['2'])  # Same as --only 2
report = SuiteExecutor().run(context, timeout=5)  # Same as --timeout 5
print(report.as_dict()['groups'])

Validation

You can validate a Baygon configuration file with the baygon.Schema function:

import baygon

data = baygon.Schema({
    'version': 1,
    'tests': [{
        'name': 'Test',
        'exit': 0
    }]
})

assert(data['version'], 1)