examples: fixed passjob.py with automatic case and added a custom case

Adding here some some possible use case of the current API. So far I
notice that we have two big cases: automatic job discovery vs
manual/custom job. I understand that there is room for improvements but
I would like to keep things consistent and intuitive here, because of
that this work is separating the logic behind the constructors and the
from_config() methods for both: Job() and TestSuite().
Signed-off-by: NBeraldo Leal <bleal@redhat.com>
上级 1a7575c6
#!/usr/bin/env python3
import sys
from avocado.core.job import Job
from avocado.core.suite import TestSuite
config = {'run.references': ['examples/tests/passtest.py:PassTest.test']}
job_config = {'run.test_runner': 'nrunner',
'run.references': ['examples/tests/passtest.py:PassTest.test']}
# Automatic helper method (Avocado will try to discovery things from config
# dicts. Since there is magic here, we dont need to pass suite names or suites,
# and test/task id will be prepend with the suite index (in this case 1 and 2)
suite = TestSuite.from_config(config)
with Job(config, [suite]) as j:
sys.exit(j.run())
job = Job.from_config(job_config=job_config)
job.setup()
sys.exit(job.run())
import sys
from avocado.core.job import Job
from avocado.core.suite import TestSuite
job_config = {'run.test_runner': 'nrunner'}
config1 = {'run.references': ['examples/tests/passtest.py:PassTest.test']}
config2 = {'run.references': ['examples/tests/passtest.py:PassTest.test']}
# Custom method (no discovery, no guess, no magic)
# Since there is no magic, we need to pass a suite name, otherwise a uuid4 will
# be used for suite.name. Also run.references will be ignored (Avocado will not
# creating tests suites for you).
suite1 = TestSuite(config=config1, tests=[], name='suite1')
suite2 = TestSuite(config=config2, tests=[], name='suite2')
with Job(job_config, [suite1, suite2]) as j:
sys.exit(j.run())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册