docs: Fix references to the params API

We forgot to update all places where the params API
was referenced, leaving us with old constructs in code
samples, such as referring to a params key by
self.params.key.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 c8518bc4
......@@ -38,32 +38,31 @@ Let's re-create an old time favorite, ``sleeptest``, which is a functional
test for avocado (old because we also use such a test for autotest). It does
nothing but ``time.sleep([number-seconds])``::
#!/usr/bin/python
#!/usr/bin/python
import time
import time
from avocado import test
from avocado import main
from avocado import test
from avocado import main
class SleepTest(test.Test):
class SleepTest(test.Test):
"""
Example test for avocado.
"""
default_params = {'sleep_length': 1.0}
def runTest(self):
"""
Sleep for length seconds.
Example test for avocado.
"""
self.log.debug("Sleeping for %.2f seconds", self.params.sleep_length)
time.sleep(self.params.sleep_length)
def runTest(self):
"""
Sleep for length seconds.
"""
sleep_length = self.params.get('sleep_length', default=1)
self.log.debug("Sleeping for %.2f seconds", sleep_length)
time.sleep(sleep_length)
if __name__ == "__main__":
main()
if __name__ == "__main__":
main()
This is about the simplest test you can write for avocado (at least, one using
the avocado APIs). An avocado test is basically a class that inherits from
......@@ -89,16 +88,17 @@ automatically saved to test results (as long as the output format supports it).
If you choose to save binary data to the whiteboard, it's your responsibility to
encoded it first (base64 is the obvious choice).
Building on the previously demonstrated sleeptest, suppose that you want to save the
Building on the previously demonstrated ``sleeptest``, suppose that you want to save the
sleep length to be used by some other script or data analysis tool::
def runTest(self):
"""
Sleep for length seconds.
"""
self.log.debug("Sleeping for %.2f seconds", self.params.sleep_length)
time.sleep(self.params.sleep_length)
self.whiteboard = "%.2f" % self.params.sleep_length
sleep_length = self.params.get('sleep_length', default=1)
self.log.debug("Sleeping for %.2f seconds", sleep_length)
time.sleep(sleep_length)
self.whiteboard = "%.2f" % sleep_length
The whiteboard can and should be exposed by files generated by the available test result
plugins. The ``results.json`` file already includes the whiteboard for each test.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册