This module provides functions that give test authors hints as to which platform their tests are currently running on. This is useful when a test needs to test slight different behavior depending on the system it’s running on. For example:
from autopilot import platform
...
def test_something(self):
if platform.model() == "Galaxy Nexus":
# do something
elif platform.model() == "Desktop":
# do something else
def test_something_else(self):
if platform.is_tablet():
# run a tablet test
else:
# run a non-tablet test
Sometimes you want a test to not run on certain platforms, or only run on certain platforms. This can be easily achieved with a combination of the functions in this module and the skipIf and skipUnless decorators. For example, to define a test that only runs on the galaxy nexus device, write this:
from testtools import skipUnless
...
@skipUnless(
platform.model() == 'Galaxy Nexus',
"Test is only for Galaxy Nexus"
)
def test_something(self):
# test things!
The inverse is possible as well. To define a test that will run on every device except the Galaxy Nexus, write this:
from testtools import skipIf
...
@skipIf(
platform.model() == 'Galaxy Nexus',
"Test not available for Galaxy Nexus"
)
def test_something(self):
# test things!
Tuples of values can be used as well, to select more than one platform. For example:
@skipIf(
platform.model() in ('Model One', 'Model Two'),
"Test not available for Models One and Two"
)
def test_something(self):
# test things!
Get the model name of the current platform.
For desktop / laptop installations, this will return “Desktop”. Otherwise, the current hardware model will be returned. For example:
platform.model()
... "Galaxy Nexus"